class DirectoryLoader
Represents a directory which contains bakefiles.
Definitions
def initialize(root, name: nil)
Initialize the loader with the specified root path.
Signature
-
parameter
root
String
A file-system path.
Implementation
def initialize(root, name: nil)
@root = root
@name = name
end
attr :root
The root path for this loader.
def each
Enumerate all bakefiles within the loaders root directory.
You can pass the yielded path to scope_for
to load the corresponding module Bake::Scope
.
Signature
-
yields
{|path| ...}
-
parameter
path
String
The (relative) scope path.
-
parameter
Implementation
def each
return to_enum unless block_given?
Dir.glob("**/*.rb", base: @root) do |file_path|
yield file_path.sub(/\.rb$/, '').split(File::SEPARATOR)
end
end
def scopes_for(path)
Load the module Bake::Scope
for the specified relative path within this loader, if it exists.
Signature
-
parameter
path
Array(String)
A relative path.
Implementation
def scopes_for(path)
*directory, file = *path
file_path = File.join(@root, directory, "#{file}.rb")
if File.exist?(file_path)
yield Scope.load(file_path, path)
end
end