class Bake::Loaders
Structured access to the working directory and loaded gems for loading bakefiles.
def self.default(working_directory)
Create a loader using the specified working directory.
def self.default(working_directory) loaders = self.new loaders.append_defaults(working_directory) return loaders end
def append_defaults(working_directory)
Add loaders according to the current working directory and loaded gems.
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
def append_from_gems
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
def append_from_root(current = Dir.pwd, **options)
Search from the current working directory until a suitable bakefile is found and add it.
def append_from_root(current = Dir.pwd, **options) while current append_path(current, **options) parent = File.dirname(current) if current == parent break else current = parent end end end
def append_path(current = Dir.pwd, **options)
The computed path will have `bake` appended to it.
Append a specific project path to the search path for recipes.
def append_path(current = Dir.pwd, **options) bake_path = File.join(current, "bake") if File.directory?(bake_path) return insert(bake_path, **options) end return false end
def each(&block)
def each(&block) @ordered.each(&block) end
def empty?
Whether any loaders are defined.
def empty? @ordered.empty? end
def initialize
def initialize @roots = {} @ordered = Array.new end
def insert(directory, **options)
def insert(directory, **options) unless @roots.key?(directory) Console.logger.debug(self) {"Adding #{directory.inspect}"} loader = Loader.new(directory, **options) @roots[directory] = loader @ordered << loader return true end return false end