module FlowMachine::WorkflowState::CallbackDsl
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
Public Instance Methods
after_change(field, *args, &block)
click to toggle source
Happens after persistence if the field on the object has changed
# 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)
click to toggle source
Called after `persist` when the workflow transitioned into this state
# 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)
click to toggle source
Happens before persistence if the field on the object has changed
# 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)
click to toggle source
Called when the workflow `transition`s to the state
# 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)
click to toggle source
Called when the worklow `transition`s out of the state
# File lib/flow_machine/workflow_state.rb, line 84 def on_exit(*args, &block) add_callback(:on_exit, FlowMachine::StateCallback.new(*args, &block)) end
Private Instance Methods
add_callback(hook, callback)
click to toggle source
# File lib/flow_machine/workflow_state.rb, line 100 def add_callback(hook, callback) self.state_callbacks ||= {} state_callbacks[hook] ||= [] state_callbacks[hook] << callback end