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.
This commit is contained in:
Thibault Jouan
2013-08-17 20:27:17 +00:00
parent 639bdc1c73
commit 3a0ce82799
2 changed files with 60 additions and 6 deletions

View File

@@ -4,13 +4,23 @@ module Producer
class DSL
class << self
def evaluate(env, &block)
dsl = new(&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
def initialize(&block)
@block = block
attr_accessor :tests
def initialize(env, &block)
@env = env
@block = block
@tests = []
end
def evaluate