Class: Bake::Loaders
Overview
Structured access to the working directory and loaded gems for loading bakefiles.
Class Method Summary collapse
-
.default(working_directory) ⇒ Object
Create a loader using the specified working directory.
Instance Method Summary collapse
-
#append_defaults(working_directory) ⇒ Object
Add loaders according to the current working directory and loaded gems.
-
#append_from_gems ⇒ Object
Enumerate all loaded gems and add them.
-
#append_from_root(current = Dir.pwd, **options) ⇒ Object
Search from the current working directory until a suitable bakefile is found and add it.
-
#append_path(current = Dir.pwd, **options) ⇒ Object
Append a specific project path to the search path for recipes.
-
#each(&block) ⇒ Object
Enumerate the loaders in order.
-
#empty? ⇒ Boolean
Whether any loaders are defined.
-
#initialize ⇒ Loaders
constructor
Initialize an empty array of loaders.
Constructor Details
#initialize ⇒ Loaders
Initialize an empty array of loaders.
41 42 43 44 |
# File 'lib/bake/loaders.rb', line 41 def initialize @roots = {} @ordered = Array.new end |
Class Method Details
.default(working_directory) ⇒ Object
Create a loader using the specified working directory.
32 33 34 35 36 37 38 |
# File 'lib/bake/loaders.rb', line 32 def self.default(working_directory) loaders = self.new loaders.append_defaults(working_directory) return loaders end |
Instance Method Details
#append_defaults(working_directory) ⇒ Object
Add loaders according to the current working directory and loaded gems.
54 55 56 57 58 59 60 |
# File 'lib/bake/loaders.rb', line 54 def append_defaults(working_directory) # Load recipes from working directory: self.append_path(working_directory) # Load recipes from loaded gems: self.append_from_gems end |
#append_from_gems ⇒ Object
Enumerate all loaded gems and add them.
97 98 99 100 101 102 103 104 105 |
# File 'lib/bake/loaders.rb', line 97 def append_from_gems Gem.loaded_specs.each do |name, spec| Console.logger.debug(self) {"Checking gem #{name}: #{spec.full_gem_path}..."} if path = spec.full_gem_path and File.directory?(path) append_path(path, name: spec.full_name) end end end |
#append_from_root(current = Dir.pwd, **options) ⇒ Object
Search from the current working directory until a suitable bakefile is found and add it.
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/bake/loaders.rb', line 82 def append_from_root(current = Dir.pwd, **) while current append_path(current, **) parent = File.dirname(current) if current == parent break else current = parent end end end |
#append_path(current = Dir.pwd, **options) ⇒ Object
Append a specific project path to the search path for recipes. The computed path will have ‘bake` appended to it.
70 71 72 73 74 75 76 77 78 |
# File 'lib/bake/loaders.rb', line 70 def append_path(current = Dir.pwd, **) bake_path = File.join(current, "bake") if File.directory?(bake_path) return insert(bake_path, **) end return false end |
#each(&block) ⇒ Object
Enumerate the loaders in order.
63 64 65 |
# File 'lib/bake/loaders.rb', line 63 def each(&block) @ordered.each(&block) end |
#empty? ⇒ Boolean
Whether any loaders are defined.
48 49 50 |
# File 'lib/bake/loaders.rb', line 48 def empty? @ordered.empty? end |