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.
33 lines
627 B
Ruby
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
|