Module: FlowMachine::WorkflowState::CallbackDsl
- Included in:
- FlowMachine::WorkflowState
- Defined in:
- lib/flow_machine/workflow_state.rb
Overview
Callbacks may be a symbol method name on the state, workflow, or underlying object, and will look for that method on those objects in that order. You may also use a block. Callbacks will accept :if and :unless options, which also may be method name symbols or blocks. The option accepts an array meaning all methods must return true (for if) and false (for unless)
class ExampleState < Workflow::State
on_enter :some_method, if: :allowed?
after_enter :after_enter_method, if: [:this_is_true?, :and_this_is_true?]
before_change(:field_name) { do_something }
end
Instance Method Summary collapse
-
#after_change(field, *args, &block) ⇒ Object
Happens after persistence if the field on the object has changed.
-
#after_enter(*args, &block) ⇒ Object
Called after ‘persist` when the workflow transitioned into this state.
-
#before_change(field, *args, &block) ⇒ Object
Happens before persistence if the field on the object has changed.
-
#on_enter(*args, &block) ⇒ Object
Called when the workflow ‘transition`s to the state.
-
#on_exit(*args, &block) ⇒ Object
Called when the worklow ‘transition`s out of the state.
Instance Method Details
#after_change(field, *args, &block) ⇒ Object
Happens after persistence if the field on the object has changed
94 95 96 |
# File 'lib/flow_machine/workflow_state.rb', line 94 def after_change(field, *args, &block) add_callback(:after_change, FlowMachine::ChangeCallback.new(field, *args, &block)) end |
#after_enter(*args, &block) ⇒ Object
Called after ‘persist` when the workflow transitioned into this state
79 80 81 |
# File 'lib/flow_machine/workflow_state.rb', line 79 def after_enter(*args, &block) add_callback(:after_enter, FlowMachine::StateCallback.new(*args, &block)) end |
#before_change(field, *args, &block) ⇒ Object
Happens before persistence if the field on the object has changed
89 90 91 |
# File 'lib/flow_machine/workflow_state.rb', line 89 def before_change(field, *args, &block) add_callback(:before_change, FlowMachine::ChangeCallback.new(field, *args, &block)) end |
#on_enter(*args, &block) ⇒ Object
Called when the workflow ‘transition`s to the state
74 75 76 |
# File 'lib/flow_machine/workflow_state.rb', line 74 def on_enter(*args, &block) add_callback(:on_enter, FlowMachine::StateCallback.new(*args, &block)) end |
#on_exit(*args, &block) ⇒ Object
Called when the worklow ‘transition`s out of the state
84 85 86 |
# File 'lib/flow_machine/workflow_state.rb', line 84 def on_exit(*args, &block) add_callback(:on_exit, FlowMachine::StateCallback.new(*args, &block)) end |