Class: Operations::Task::Plan::WaitHandler
- Inherits:
-
Object
- Object
- Operations::Task::Plan::WaitHandler
- Defined in:
- app/models/operations/task/plan/wait_handler.rb
Instance Method Summary collapse
- #call(task) ⇒ Object
- #condition(options = {}, &condition) ⇒ Object
- #condition_labels ⇒ Object
- #go_to(state) ⇒ Object
- #immediate? ⇒ Boolean
-
#initialize(name, &config) ⇒ WaitHandler
constructor
A new instance of WaitHandler.
Constructor Details
#initialize(name, &config) ⇒ WaitHandler
Returns a new instance of WaitHandler.
2 3 4 5 6 7 |
# File 'app/models/operations/task/plan/wait_handler.rb', line 2 def initialize name, &config @name = name.to_sym @conditions = [] @destinations = [] instance_eval(&config) end |
Instance Method Details
#call(task) ⇒ Object
22 23 24 25 26 27 |
# File 'app/models/operations/task/plan/wait_handler.rb', line 22 def call(task) Rails.logger.debug { "#{task}: waiting until #{@name}" } condition = @conditions.find { |condition| task.instance_eval(&condition) } next_state = (condition.nil? || @conditions.index(condition).nil?) ? task.current_state : @destinations[@conditions.index(condition)] task.go_to next_state end |
#condition(options = {}, &condition) ⇒ Object
11 12 13 14 15 16 |
# File 'app/models/operations/task/plan/wait_handler.rb', line 11 def condition( = {}, &condition) @conditions << condition @condition_labels ||= {} condition_index = @conditions.size - 1 @condition_labels[condition_index] = [:label] if [:label] end |
#condition_labels ⇒ Object
20 |
# File 'app/models/operations/task/plan/wait_handler.rb', line 20 def condition_labels = @condition_labels ||= {} |
#go_to(state) ⇒ Object
18 |
# File 'app/models/operations/task/plan/wait_handler.rb', line 18 def go_to(state) = @destinations << state |
#immediate? ⇒ Boolean
9 |
# File 'app/models/operations/task/plan/wait_handler.rb', line 9 def immediate? = false |