class Bake::Loaders

def self.default(working_directory)

def self.default(working_directory)
	loaders = self.new
	
	loaders.append_defaults(working_directory)
	
	return loaders
end

def append_defaults(working_directory)

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_paths(paths, **options)

def append_from_paths(paths, **options)
	paths.each do |path|
		append_path(path, **options)
	end
end

def append_from_root(current = Dir.pwd, **options)

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)

def append_path(current = Dir.pwd, **options)
	recipes_path = File.join(current, "recipes")
	bake_path = File.join(current, "bake")
	
	if File.directory?(bake_path)
		return insert(bake_path, **options)
	end
	
	if File.directory?(recipes_path)
		Console.logger.warn(self) do |buffer|
			buffer.puts "Recipes path: #{recipes_path.inspect} is deprecated."
			buffer.puts "Please use #{bake_path.inspect} instead."
		end
		
		return insert(recipes_path, **options)
	end
	
	return false
end

def each(&block)

def each(&block)
	return to_enum unless block_given?
	
	@ordered.each(&block)
end

def empty?

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