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.
43 lines
944 B
Ruby
43 lines
944 B
Ruby
module Producer
|
|
module Core
|
|
class Task
|
|
class DSL
|
|
class << self
|
|
def evaluate(name, env, &block)
|
|
dsl = new(&block)
|
|
dsl.evaluate(env)
|
|
Task.new(name, dsl.actions, dsl.condition)
|
|
end
|
|
|
|
def define_action(keyword, klass)
|
|
define_method(keyword) do |*args|
|
|
@actions << klass.new(@env, *args)
|
|
end
|
|
end
|
|
end
|
|
|
|
define_action :echo, Actions::Echo
|
|
define_action :sh, Actions::ShellCommand
|
|
|
|
attr_accessor :actions
|
|
|
|
def initialize(&block)
|
|
@block = block
|
|
@actions = []
|
|
@condition = true
|
|
end
|
|
|
|
def evaluate(env)
|
|
@env = env
|
|
instance_eval &@block
|
|
end
|
|
|
|
def condition(&block)
|
|
@condition = Condition.evaluate(@env, &block) if block
|
|
@condition
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|