Class: Bake::Loader
- Inherits:
-
Object
- Object
- Bake::Loader
- Defined in:
- lib/bake/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) ⇒ Loader
constructor
Initialize the loader with the specified root path.
-
#scope_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) ⇒ Loader
Initialize the loader with the specified root path.
28 29 30 31 |
# File 'lib/bake/loader.rb', line 28 def initialize(root, name: nil) @root = root @name = name end |
Instance Attribute Details
#root ⇒ Object (readonly)
The root path for this loader.
38 39 40 |
# File 'lib/bake/loader.rb', line 38 def root @root end |
Instance Method Details
#each ⇒ Object
Enumerate all bakefiles within the loaders root directory.
43 44 45 46 47 48 49 |
# File 'lib/bake/loader.rb', line 43 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 |
#scope_for(path) ⇒ Object
Load the Scope for the specified relative path within this loader, if it exists.
53 54 55 56 57 58 59 60 61 |
# File 'lib/bake/loader.rb', line 53 def scope_for(path) *directory, file = *path file_path = File.join(@root, directory, "#{file}.rb") if File.exist?(file_path) return Scope.load(file_path, path) end end |
#to_s ⇒ Object
33 34 35 |
# File 'lib/bake/loader.rb', line 33 def to_s "#{self.class} #{@name || @root}" end |