In Condition: * Modify constructor to accepts tests and a default return value; * Implement #met?; * Modify #! so that it return the negated value returned by #met?. In Condition::DSL: * Modify .evaluate to build the condition with tests and the value returned by a the evaluated condition block. Add a basic Test base class, with env and arguments as attributes. Add some spec helpers to build some easily testable kind of Test instances (as test doubles).
34 lines
688 B
Ruby
34 lines
688 B
Ruby
module Producer
|
|
module Core
|
|
class Condition
|
|
class DSL
|
|
class << self
|
|
def evaluate(env, &block)
|
|
dsl = new(env, &block)
|
|
return_value = dsl.evaluate
|
|
Condition.new(dsl.tests, return_value)
|
|
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
|
|
instance_eval &@block
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|