class Bake::Context

def self.load(file_path, loaders = nil)

def self.load(file_path, loaders = nil)
	scope = Scope.load(file_path)
	
	unless loaders
		if scope.respond_to?(:loaders)
			loaders = scope.loaders
		else
			working_directory = File.dirname(file_path)
			loaders = Loaders.default(working_directory)
		end
	end
	
	self.new(scope, loaders)
end

def base_for(path)

Parameters:
  • scope (Array) -- the path for the scope.
def base_for(path)
	base = nil
	
	@loaders.each do |loader|
		if scope = loader.scope_for(path)
			base ||= Base.derive(path)
			
			base.prepend(scope)
		end
	end
	
	return base
end

def call(*commands)

def call(*commands)
	while command = commands.shift
		if recipe = @recipes[command]
			arguments, options = recipe.prepare(commands)
			recipe.call(*arguments, **options)
		else
			raise ArgumentError, "Could not find recipe for #{command}!"
		end
	end
end

def initialize(scope, loaders, **options)

def initialize(scope, loaders, **options)
	base = Base.derive
	base.prepend(scope)
	
	@loaders = loaders
	
	@stack = []
	
	@scopes = Hash.new do |hash, key|
		hash[key] = scope_for(key)
	end
	
	@scope = base.new(self)
	@scopes[[]] = @scope
	
	@recipes = Hash.new do |hash, key|
		hash[key] = recipe_for(key)
	end
end

def lookup(command)

def lookup(command)
	@recipes[command]
end

def recipe_for(command)

def recipe_for(command)
	path = command.split(":")
	
	if scope = @scopes[path]
		return scope.recipe_for(path.last)
	else
		*path, name = *path
		
		if scope = @scopes[path]
			return scope.recipe_for(name)
		end
	end
	
	return nil
end

def scope_for(path)

def scope_for(path)
	if base = base_for(path)
		return base.new(self)
	end
end

def with!(scope)

def with!(scope)
	@stack << scope
	
	yield
ensure
	@scope.pop
end