class Workflow::Specification

Attributes

after_transition_proc[RW]
before_transition_proc[RW]
initial_state[RW]
meta[RW]
on_error_proc[RW]
on_transition_proc[RW]
states[RW]

Public Class Methods

new(meta = {}, &specification) click to toggle source
# File lib/workflow/specification.rb, line 11
def initialize(meta = {}, &specification)
  @states = Hash.new
  @meta = meta
  instance_eval(&specification)
end

Public Instance Methods

state_names() click to toggle source
# File lib/workflow/specification.rb, line 17
def state_names
  states.keys
end

Private Instance Methods

after_transition(&proc) click to toggle source
# File lib/workflow/specification.rb, line 51
def after_transition(&proc)
  @after_transition_proc = proc
end
before_transition(&proc) click to toggle source
# File lib/workflow/specification.rb, line 55
def before_transition(&proc)
  @before_transition_proc = proc
end
event(name, args = {}, &action) click to toggle source
# File lib/workflow/specification.rb, line 32
def event(name, args = {}, &action)
  target = args[:transitions_to] || args[:transition_to]
  condition = args[:if]
  raise WorkflowDefinitionError.new(
    "missing ':transitions_to' in workflow event definition for '#{name}'") \
    if target.nil?
  @scoped_state.events.push(
    name, Workflow::Event.new(name, target, condition, (args[:meta] or {}), &action)
  )
end
on_entry(&proc) click to toggle source
# File lib/workflow/specification.rb, line 43
def on_entry(&proc)
  @scoped_state.on_entry = proc
end
on_error(&proc) click to toggle source
# File lib/workflow/specification.rb, line 63
def on_error(&proc)
  @on_error_proc = proc
end
on_exit(&proc) click to toggle source
# File lib/workflow/specification.rb, line 47
def on_exit(&proc)
  @scoped_state.on_exit = proc
end
on_transition(&proc) click to toggle source
# File lib/workflow/specification.rb, line 59
def on_transition(&proc)
  @on_transition_proc = proc
end
state(name, meta = {:meta => {}}, &events_and_etc) click to toggle source
# File lib/workflow/specification.rb, line 23
def state(name, meta = {:meta => {}}, &events_and_etc)
  # meta[:meta] to keep the API consistent..., gah
  new_state = Workflow::State.new(name, self, 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