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).
27 lines
489 B
Ruby
27 lines
489 B
Ruby
module Producer
|
|
module Core
|
|
class Condition
|
|
class << self
|
|
def evaluate(env, &block)
|
|
DSL.evaluate(env, &block)
|
|
end
|
|
end
|
|
|
|
def initialize(tests, return_value = nil)
|
|
@tests = tests
|
|
@return_value = return_value
|
|
end
|
|
|
|
def met?
|
|
return !!@return_value if @tests.empty?
|
|
@tests.each { |t| return false unless t.success? }
|
|
true
|
|
end
|
|
|
|
def !
|
|
!met?
|
|
end
|
|
end
|
|
end
|
|
end
|