class Workflow::Specification
Attributes
initial_state[RW]
meta[RW]
on_failed_transition_proc[RW]
on_transition_proc[RW]
states[RW]
Public Class Methods
new(meta = {}, &specification)
click to toggle source
# File lib/workflow.rb, line 15 def initialize(meta = {}, &specification) @states = Hash.new @meta = meta instance_eval(&specification) end
Public Instance Methods
event_names()
click to toggle source
# File lib/workflow.rb, line 25 def event_names states.values.map{|e| e.events.keys }.uniq end
state_names()
click to toggle source
# File lib/workflow.rb, line 21 def state_names states.keys end
Private Instance Methods
allow(name, args={}, &action)
click to toggle source
# File lib/workflow.rb, line 50 def allow(name, args={}, &action) args[:transitions_to] ||= args[:transition_to] || @scoped_state.to_sym event name, args, &action end
event(name, args = {}, &action)
click to toggle source
# File lib/workflow.rb, line 40 def event(name, args = {}, &action) target = args[:transitions_to] || args[:transition_to] if target.nil? raise WorkflowDefinitionError.new \ "missing ':transitions_to' in workflow event definition for '#{name}'" end @scoped_state.events[name.to_sym] = Workflow::Event.new(name, target, (args[:meta] || {}), &action) end
on_entry(&proc_to_run)
click to toggle source
# File lib/workflow.rb, line 55 def on_entry(&proc_to_run) @scoped_state.on_entry = proc_to_run end
on_exit(&proc_to_run)
click to toggle source
# File lib/workflow.rb, line 59 def on_exit(&proc_to_run) @scoped_state.on_exit = proc_to_run end
on_failed_transition(&proc_to_run)
click to toggle source
# File lib/workflow.rb, line 67 def on_failed_transition(&proc_to_run) @on_failed_transition_proc = proc_to_run end
on_transition(&proc_to_run)
click to toggle source
# File lib/workflow.rb, line 63 def on_transition(&proc_to_run) @on_transition_proc = proc_to_run end
state(name, meta = {:meta => {}}, &events_and_etc)
click to toggle source
# File lib/workflow.rb, line 31 def state(name, meta = {:meta => {}}, &events_and_etc) # meta[:meta] to keep the API consistent..., gah new_state = Workflow::State.new(name, meta[:meta]) @initial_state = new_state if @states.empty? @states[name.to_sym] = new_state @scoped_state = new_state instance_eval(&events_and_etc) if events_and_etc end