Thibault Jouan 3a0ce82799 Improve Condition DSL framework:
Add the necessary API so that we can implement new tests easily as new
standalone classes.

  In Condition::DSL:

* Add #tests accessor;
* Modify constructor so that it accepts the env;
* Implement .define_test(keyword, class) method.
2013-08-18 00:29:36 +00:00

33 lines
627 B
Ruby

module Producer
module Core
class Condition
class DSL
class << self
def evaluate(env, &block)
dsl = new(env, &block)
Condition.new(dsl.evaluate)
end
def define_test(keyword, klass)
define_method(keyword) do |*args|
@tests << klass.new(@env, *args)
end
end
end
attr_accessor :tests
def initialize(env, &block)
@env = env
@block = block
@tests = []
end
def evaluate
@block.call
end
end
end
end
end