Class: Stately::Machine
- Inherits:
-
Object
- Object
- Stately::Machine
- Defined in:
- lib/stately/machine.rb
Overview
A Stately::Machine is a container for Stately::States.
Instance Attribute Summary collapse
-
#start ⇒ Object
readonly
Returns the value of attribute start.
-
#state_attr ⇒ Object
readonly
Returns the value of attribute state_attr.
-
#states ⇒ Object
readonly
Returns the value of attribute states.
Instance Method Summary collapse
-
#initialize(attr_name, start) ⇒ Machine
constructor
Sets up a new instance of Stately::Machine.
-
#state(name, opts = {}, &block) ⇒ Object
Define a new Stately::State and add it to this Stately::Machine.
Constructor Details
#initialize(attr_name, start) ⇒ Machine
Sets up a new instance of Stately::Machine
7 8 9 10 11 |
# File 'lib/stately/machine.rb', line 7 def initialize(attr_name, start) @state_attr = attr_name @start = start @states = [State.new(@start)] end |
Instance Attribute Details
#start ⇒ Object (readonly)
Returns the value of attribute start.
4 5 6 |
# File 'lib/stately/machine.rb', line 4 def start @start end |
#state_attr ⇒ Object (readonly)
Returns the value of attribute state_attr.
4 5 6 |
# File 'lib/stately/machine.rb', line 4 def state_attr @state_attr end |
#states ⇒ Object (readonly)
Returns the value of attribute states.
4 5 6 |
# File 'lib/stately/machine.rb', line 4 def states @states end |
Instance Method Details
#state(name, opts = {}, &block) ⇒ Object
Define a new Stately::State and add it to this Stately::Machine.
19 20 21 22 23 24 |
# File 'lib/stately/machine.rb', line 19 def state(name, opts={}, &block) @states.delete_if { |s| s.name == name } action = opts ? opts[:action] : nil @states << State.new(name, action, &block) end |