Class: FlowMachine::WorkflowState
- Inherits:
-
Object
- Object
- FlowMachine::WorkflowState
- Extended by:
- CallbackDsl, ClassMethods
- Defined in:
- lib/flow_machine/workflow_state.rb
Defined Under Namespace
Modules: CallbackDsl, ClassMethods
Instance Attribute Summary collapse
-
#guard_errors ⇒ Object
Returns the value of attribute guard_errors.
-
#workflow ⇒ Object
readonly
Returns the value of attribute workflow.
Attributes included from ClassMethods
#expose_to_workflow_methods, #state_callbacks
Instance Method Summary collapse
- #==(other) ⇒ Object
- #fire_callback_list(callbacks, changes = {}) ⇒ Object
- #fire_callbacks(event, changes = {}) ⇒ Object
-
#initialize(workflow) ⇒ WorkflowState
constructor
A new instance of WorkflowState.
- #name ⇒ Object
-
#run_workflow_method(method_name, *args, &block) ⇒ Object
Allows method calls to fallback up the object chain so guards and other methods can be defined on the object or workflow as well as the state.
- #transition(options = {}) ⇒ Object
Methods included from ClassMethods
event, expose_to_workflow, state_name
Methods included from CallbackDsl
after_change, after_enter, before_change, on_enter
Constructor Details
#initialize(workflow) ⇒ WorkflowState
101 102 103 104 |
# File 'lib/flow_machine/workflow_state.rb', line 101 def initialize(workflow) @workflow = workflow @guard_errors = [] end |
Instance Attribute Details
#guard_errors ⇒ Object
Returns the value of attribute guard_errors.
6 7 8 |
# File 'lib/flow_machine/workflow_state.rb', line 6 def guard_errors @guard_errors end |
#workflow ⇒ Object (readonly)
Returns the value of attribute workflow.
5 6 7 |
# File 'lib/flow_machine/workflow_state.rb', line 5 def workflow @workflow end |
Instance Method Details
#==(other) ⇒ Object
138 139 140 |
# File 'lib/flow_machine/workflow_state.rb', line 138 def ==(other) self.class == other.class end |
#fire_callback_list(callbacks, changes = {}) ⇒ Object
106 107 108 109 110 |
# File 'lib/flow_machine/workflow_state.rb', line 106 def fire_callback_list(callbacks, changes = {}) callbacks.each do |callback| callback.call(self, changes) end end |
#fire_callbacks(event, changes = {}) ⇒ Object
112 113 114 115 |
# File 'lib/flow_machine/workflow_state.rb', line 112 def fire_callbacks(event, changes = {}) return unless self.class.state_callbacks.try(:[], event) fire_callback_list self.class.state_callbacks[event], changes end |
#name ⇒ Object
134 135 136 |
# File 'lib/flow_machine/workflow_state.rb', line 134 def name self.class.state_name end |
#run_workflow_method(method_name, *args, &block) ⇒ Object
Allows method calls to fallback up the object chain so guards and other methods can be defined on the object or workflow as well as the state
120 121 122 123 124 125 126 |
# File 'lib/flow_machine/workflow_state.rb', line 120 def run_workflow_method(method_name, *args, &block) if target = object_chain(method_name) target.send(method_name, *args, &block) else raise NoMethodError.new("undefined method #{method_name}", method_name) end end |
#transition(options = {}) ⇒ Object
128 129 130 131 132 |
# File 'lib/flow_machine/workflow_state.rb', line 128 def transition( = {}) workflow.transition().tap do |new_state| new_state.fire_callbacks(:on_enter) if new_state end end |