Class: Bake::Registry::DirectoryLoader
- Inherits:
-
Object
- Object
- Bake::Registry::DirectoryLoader
- Defined in:
- lib/bake/registry/directory_loader.rb
Overview
Represents a directory which contains bakefiles.
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
The root path for this loader.
Instance Method Summary collapse
-
#each ⇒ Object
Enumerate all bakefiles within the loaders root directory.
-
#initialize(root, name: nil) ⇒ DirectoryLoader
constructor
Initialize the loader with the specified root path.
-
#scopes_for(path) ⇒ Object
Load the Scope for the specified relative path within this loader, if it exists.
- #to_s ⇒ Object
Constructor Details
#initialize(root, name: nil) ⇒ DirectoryLoader
Initialize the loader with the specified root path.
14 15 16 17 |
# File 'lib/bake/registry/directory_loader.rb', line 14 def initialize(root, name: nil) @root = root @name = name end |
Instance Attribute Details
#root ⇒ Object (readonly)
The root path for this loader.
24 25 26 |
# File 'lib/bake/registry/directory_loader.rb', line 24 def root @root end |
Instance Method Details
#each ⇒ Object
Enumerate all bakefiles within the loaders root directory.
You can pass the yielded path to scope_for to load the corresponding Scope.
32 33 34 35 36 37 38 |
# File 'lib/bake/registry/directory_loader.rb', line 32 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 |
#scopes_for(path) ⇒ Object
Load the Scope for the specified relative path within this loader, if it exists.
42 43 44 45 46 47 48 49 50 |
# File 'lib/bake/registry/directory_loader.rb', line 42 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 |
#to_s ⇒ Object
19 20 21 |
# File 'lib/bake/registry/directory_loader.rb', line 19 def to_s "#{self.class} #{@name || @root}" end |