Module: Workflow::InstanceMethods
- Defined in:
- lib/workflow.rb
Instance Method Summary collapse
- #current_state ⇒ Object
- #halt(reason = nil) ⇒ Object
- #halt!(reason = nil) ⇒ Object
-
#halted? ⇒ Boolean
See the ‘Guards’ section in the README.
-
#halted_because ⇒ Object
call of ‘halt` or `halt!` method.
- #process_event!(name, *args) ⇒ Object
- #spec ⇒ Object
Instance Method Details
#current_state ⇒ Object
80 81 82 83 84 |
# File 'lib/workflow.rb', line 80 def current_state loaded_state = load_workflow_state res = spec.states[loaded_state.to_sym] if loaded_state res || spec.initial_state end |
#halt(reason = nil) ⇒ Object
135 136 137 138 |
# File 'lib/workflow.rb', line 135 def halt(reason = nil) @halted_because = reason @halted = true end |
#halt!(reason = nil) ⇒ Object
140 141 142 143 144 |
# File 'lib/workflow.rb', line 140 def halt!(reason = nil) @halted_because = reason @halted = true raise TransitionHalted.new(reason) end |
#halted? ⇒ Boolean
See the ‘Guards’ section in the README
88 89 90 |
# File 'lib/workflow.rb', line 88 def halted? @halted end |
#halted_because ⇒ Object
call of ‘halt` or `halt!` method.
94 95 96 |
# File 'lib/workflow.rb', line 94 def halted_because @halted_because end |
#process_event!(name, *args) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/workflow.rb', line 98 def process_event!(name, *args) event = current_state.events.first_applicable(name, self) raise NoTransitionAllowed.new( "There is no event #{name.to_sym} defined for the #{current_state} state") \ if event.nil? @halted_because = nil @halted = false check_transition(event) from = current_state to = spec.states[event.transitions_to] run_before_transition(from, to, name, *args) return false if @halted begin return_value = run_action(event.action, *args) || run_action_callback(event.name, *args) rescue StandardError => e run_on_error(e, from, to, name, *args) end return false if @halted run_on_transition(from, to, name, *args) run_on_exit(from, to, name, *args) transition_value = persist_workflow_state to.to_s run_on_entry(to, from, name, *args) run_after_transition(from, to, name, *args) return_value.nil? ? transition_value : return_value end |
#spec ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/workflow.rb', line 146 def spec # check the singleton class first class << self return workflow_spec if workflow_spec end c = self.class # using a simple loop instead of class_inheritable_accessor to avoid # dependency on Rails' ActiveSupport until c.workflow_spec || !(c.include? Workflow) c = c.superclass end c.workflow_spec end |