Implement basic condition DSL framework for tests:
Instead of interrupting task evaluation when condition is not met, allow the whole task to be evaluated (including condition and evaluation) so that the interpreter will get all tasks actions (whether condition is met or not) and be able to query the condition. * Modify Interpreter#process_task: test if task condition is met before applying the actions; * Implement condition handling in Task and Task::DSL; * Implement Condition and Condition::DSL (useless as they are, but needed to implement later test keywords as part of the condition DSL.
This commit is contained in:
@@ -6,7 +6,7 @@ module Producer
|
||||
def evaluate(name, env, &block)
|
||||
dsl = new(&block)
|
||||
dsl.evaluate(env)
|
||||
Task.new(name, dsl.actions)
|
||||
Task.new(name, dsl.actions, dsl.condition)
|
||||
end
|
||||
|
||||
def define_action(keyword, klass)
|
||||
@@ -22,20 +22,19 @@ module Producer
|
||||
attr_accessor :actions
|
||||
|
||||
def initialize(&block)
|
||||
@block = block
|
||||
@actions = []
|
||||
@block = block
|
||||
@actions = []
|
||||
@condition = true
|
||||
end
|
||||
|
||||
def evaluate(env)
|
||||
@env = env
|
||||
instance_eval &@block
|
||||
rescue ConditionNotMetError
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def condition(&block)
|
||||
fail ConditionNotMetError unless block.call
|
||||
@condition = Condition.evaluate(@env, &block) if block
|
||||
@condition
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user