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:
Thibault Jouan
2013-08-17 22:06:07 +00:00
parent 00a11e159f
commit ed99c191e0
10 changed files with 137 additions and 15 deletions

View File

@@ -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'

View File

@@ -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

View File

@@ -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
View 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