Class: SimpleStateMachine::StateMachineDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_state_machine/simple_state_machine.rb

Overview

Defines state machine transitions

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#decoratorObject



63
64
65
# File 'lib/simple_state_machine/simple_state_machine.rb', line 63

def decorator
  @decorator ||= @lazy_decorator.call
end

#lazy_decorator=(value) ⇒ Object (writeonly)

Sets the attribute lazy_decorator

Parameters:

  • value

    the value to set the attribute lazy_decorator to.



61
62
63
# File 'lib/simple_state_machine/simple_state_machine.rb', line 61

def lazy_decorator=(value)
  @lazy_decorator = value
end

#state_methodObject



77
78
79
# File 'lib/simple_state_machine/simple_state_machine.rb', line 77

def state_method
  @state_method ||= :state
end

Instance Method Details

#add_transition(event_name, from, to) ⇒ Object



71
72
73
74
75
# File 'lib/simple_state_machine/simple_state_machine.rb', line 71

def add_transition event_name, from, to
  transition = Transition.new(event_name, from, to)
  transitions << transition
  decorator.decorate(transition)
end

#google_chart_urlObject

Generates a url that renders states and events as a directional graph. See code.google.com/apis/chart/docs/gallery/graphviz.html



93
94
95
# File 'lib/simple_state_machine/simple_state_machine.rb', line 93

def google_chart_url
  "http://chart.googleapis.com/chart?cht=gv&chl=digraph{#{::CGI.escape to_graphiz_dot}}"
end

#to_graphiz_dotObject

Graphiz dot format for rendering as a directional graph



87
88
89
# File 'lib/simple_state_machine/simple_state_machine.rb', line 87

def to_graphiz_dot
  transitions.map { |t| t.to_graphiz_dot }.join(";")
end

#to_sObject

Human readable format: old_state.event! => new_state



82
83
84
# File 'lib/simple_state_machine/simple_state_machine.rb', line 82

def to_s
  transitions.map(&:to_s).join("\n")
end

#transitionsObject



67
68
69
# File 'lib/simple_state_machine/simple_state_machine.rb', line 67

def transitions
  @transitions ||= []
end