Implement `test_macro' recipe keyword

This commit is contained in:
Thibault Jouan
2014-06-02 10:49:05 +00:00
parent 18b835b10e
commit 3c46c5bc61
9 changed files with 197 additions and 15 deletions

View File

@@ -3,12 +3,21 @@ module Producer
class Condition
class DSL
class << self
def define_test(keyword, klass)
define_method(keyword) do |*args|
@tests << klass.new(@env, *args)
end
define_method("no_#{keyword}") do |*args|
@tests << klass.new(@env, *args, negated: true)
def define_test(keyword, test)
{
keyword => false,
"no_#{keyword}" => true
}.each do |kw, negated|
define_method(kw) do |*args|
if test.respond_to? :call
args = [test, *args]
klass = Tests::ConditionTest
else
klass = test
end
t = klass.new(@env, *args, negated: negated)
@tests << t
end
end
end
end
@@ -29,8 +38,8 @@ module Producer
@tests = []
end
def evaluate
instance_eval &@block
def evaluate(*args)
instance_exec *args, &@block
end
end
end