Build conditions with DSL evaluated tests:
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).
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
# task actions
|
||||
require 'producer/core/action'
|
||||
require 'producer/core/actions/echo'
|
||||
require 'producer/core/actions/shell_command'
|
||||
|
||||
# condition tests (need to be defined before the condition DSL)
|
||||
require 'producer/core/test'
|
||||
|
||||
require 'producer/core/cli'
|
||||
require 'producer/core/condition'
|
||||
require 'producer/core/condition/dsl'
|
||||
|
@@ -7,12 +7,19 @@ module Producer
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(expression)
|
||||
@expression = expression
|
||||
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 !
|
||||
!@expression
|
||||
!met?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -5,7 +5,8 @@ module Producer
|
||||
class << self
|
||||
def evaluate(env, &block)
|
||||
dsl = new(env, &block)
|
||||
Condition.new(dsl.evaluate)
|
||||
return_value = dsl.evaluate
|
||||
Condition.new(dsl.tests, return_value)
|
||||
end
|
||||
|
||||
def define_test(keyword, klass)
|
||||
|
12
lib/producer/core/test.rb
Normal file
12
lib/producer/core/test.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
module Producer
|
||||
module Core
|
||||
class Test
|
||||
attr_reader :env, :arguments
|
||||
|
||||
def initialize(env, *arguments)
|
||||
@env = env
|
||||
@arguments = arguments
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user