class Bake::Loaders
Structured access to the working directory and loaded gems for loading bakefiles.
Public Class Methods
default(working_directory)
click to toggle source
Create a loader using the specified working directory. @parameter working_directory [String]
# File lib/bake/loaders.rb, line 34 def self.default(working_directory) loaders = self.new loaders.append_defaults(working_directory) return loaders end
new()
click to toggle source
Initialize an empty array of loaders.
# File lib/bake/loaders.rb, line 43 def initialize @roots = {} @ordered = Array.new end
Public Instance Methods
append_defaults(working_directory)
click to toggle source
Add loaders according to the current working directory and loaded gems. @parameter working_directory [String]
# File lib/bake/loaders.rb, line 56 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()
click to toggle source
Enumerate all loaded gems and add them.
# File lib/bake/loaders.rb, line 99 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)
click to toggle source
Search from the current working directory until a suitable bakefile is found and add it. @parameter current [String] The path to start searching from.
# File lib/bake/loaders.rb, line 84 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
append_path(current = Dir.pwd, **options)
click to toggle source
Append a specific project path to the search path for recipes. The computed path will have `bake` appended to it. @parameter current [String] The path to add.
# File lib/bake/loaders.rb, line 72 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
each(&block)
click to toggle source
Enumerate the loaders in order.
# File lib/bake/loaders.rb, line 65 def each(&block) @ordered.each(&block) end
empty?()
click to toggle source
Whether any loaders are defined. @returns [Boolean]
# File lib/bake/loaders.rb, line 50 def empty? @ordered.empty? end
Protected Instance Methods
insert(directory, **options)
click to toggle source
# File lib/bake/loaders.rb, line 111 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