Class: SimpleStateMachine::StateMachineDefinition
- Inherits:
-
Object
- Object
- SimpleStateMachine::StateMachineDefinition
- Defined in:
- lib/simple_state_machine/simple_state_machine.rb
Overview
Defines state machine transitions
Instance Attribute Summary collapse
- #decorator ⇒ Object
-
#lazy_decorator ⇒ Object
writeonly
Sets the attribute lazy_decorator.
- #state_method ⇒ Object
Instance Method Summary collapse
- #add_transition(event_name, from, to) ⇒ Object
-
#google_chart_url ⇒ Object
Generates a url that renders states and events as a directional graph.
-
#to_graphiz_dot ⇒ Object
Graphiz dot format for rendering as a directional graph.
-
#to_s ⇒ Object
Human readable format: old_state.event! => new_state.
- #transitions ⇒ Object
Instance Attribute Details
#decorator ⇒ Object
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
61 62 63 |
# File 'lib/simple_state_machine/simple_state_machine.rb', line 61 def lazy_decorator=(value) @lazy_decorator = value end |
#state_method ⇒ Object
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_url ⇒ Object
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_dot ⇒ Object
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_s ⇒ Object
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 |
#transitions ⇒ Object
67 68 69 |
# File 'lib/simple_state_machine/simple_state_machine.rb', line 67 def transitions @transitions ||= [] end |