Modify recipe DSL API to take env on initialization

This commit is contained in:
Thibault Jouan
2014-01-08 22:11:38 +00:00
parent 1d6ae126ed
commit 352fcd37f8
3 changed files with 19 additions and 19 deletions

View File

@@ -3,7 +3,7 @@ module Producer
class Recipe
class << self
def evaluate_from_file(filepath, env)
dsl = DSL.new(File.read(filepath)).evaluate(env)
dsl = DSL.new(env, File.read(filepath)).evaluate
Recipe.new(dsl.tasks)
end
end

View File

@@ -2,16 +2,16 @@ module Producer
module Core
class Recipe
class DSL
attr_reader :tasks
attr_reader :env, :tasks
def initialize(code = nil, &block)
def initialize(env, code = nil, &block)
@env = env
@code = code
@block = block
@tasks = []
end
def evaluate(env)
@env = env
def evaluate
if @code
instance_eval @code
else
@@ -22,10 +22,6 @@ module Producer
private
def env
@env
end
def source(filepath)
instance_eval File.read("./#{filepath}.rb"), "#{filepath}.rb"
end