Implement `macro' recipe keyword

This commit is contained in:
Thibault Jouan
2013-12-20 09:51:15 +00:00
parent 43a781dc78
commit e8be44d1f0
7 changed files with 93 additions and 13 deletions

View File

@@ -34,8 +34,14 @@ module Producer
env.target = hostname
end
def task(name, &block)
@tasks << Task.evaluate(name, env, &block)
def task(name, *args, &block)
@tasks << Task.evaluate(name, env, *args, &block)
end
def macro(name, &block)
define_singleton_method(name) do |*args|
task("#{name}", *args, &block)
end
end
end
end

View File

@@ -2,9 +2,9 @@ module Producer
module Core
class Task
class << self
def evaluate(name, env, &block)
def evaluate(name, env, *args, &block)
dsl = DSL.new(&block)
dsl.evaluate(env)
dsl.evaluate(env, *args)
Task.new(name, dsl.actions, dsl.condition)
end
end

View File

@@ -23,9 +23,9 @@ module Producer
@condition = true
end
def evaluate(env)
def evaluate(env, *args)
@env = env
instance_eval &@block
instance_exec *args, &@block
end
def condition(&block)