Thibault Jouan c4fc9828db Improve error reporting during recipe evaluation
* Report invalid action usages from tasks;
* Implement backtrace cleaning in CLI;
* Extract error class declarations in a new errors file;
* Replace raise with fail keyword in task DSL class.
2013-08-01 20:31:39 +00:00

39 lines
806 B
Ruby

module Producer
module Core
class Recipe
class DSL
attr_reader :tasks
def initialize(code = nil, &block)
@code = code
@block = block
@tasks = []
end
def evaluate(env)
if @code
instance_eval @code, env.current_recipe.filepath
else
instance_eval &@block
end
self
rescue NameError => e
raise RecipeEvaluationError,
"invalid recipe keyword `#{e.name}'",
e.backtrace
end
private
def source(filepath)
instance_eval File.read("./#{filepath}.rb"), "#{filepath}.rb"
end
def task(name, &block)
@tasks << Task.new(name, &block)
end
end
end
end
end