Class: EdgeStateMachine::Machine
- Inherits:
-
Object
- Object
- EdgeStateMachine::Machine
- Defined in:
- lib/edge-state-machine/machine.rb
Instance Attribute Summary collapse
-
#events ⇒ Object
Returns the value of attribute events.
-
#initial_state_name ⇒ Object
readonly
Returns the value of attribute initial_state_name.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#persisted_variable_name ⇒ Object
Returns the value of attribute persisted_variable_name.
-
#states ⇒ Object
Returns the value of attribute states.
Instance Method Summary collapse
- #create_scopes(bool = false) ⇒ Object
- #create_scopes? ⇒ Boolean
- #event(name, &transitions) ⇒ Object
- #initial_state(name) ⇒ Object
-
#initialize(klass, name, &block) ⇒ Machine
constructor
A new instance of Machine.
- #persisted_to(name) ⇒ Object
- #state(name, &state) ⇒ Object
Constructor Details
#initialize(klass, name, &block) ⇒ Machine
Returns a new instance of Machine.
6 7 8 9 10 11 12 |
# File 'lib/edge-state-machine/machine.rb', line 6 def initialize(klass, name, &block) @klass = klass @name = name @states = Hash.new @events = Hash.new instance_eval(&block) if block_given? end |
Instance Attribute Details
#events ⇒ Object
Returns the value of attribute events.
3 4 5 |
# File 'lib/edge-state-machine/machine.rb', line 3 def events @events end |
#initial_state_name ⇒ Object (readonly)
Returns the value of attribute initial_state_name.
4 5 6 |
# File 'lib/edge-state-machine/machine.rb', line 4 def initial_state_name @initial_state_name end |
#klass ⇒ Object
Returns the value of attribute klass.
3 4 5 |
# File 'lib/edge-state-machine/machine.rb', line 3 def klass @klass end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/edge-state-machine/machine.rb', line 4 def name @name end |
#persisted_variable_name ⇒ Object
Returns the value of attribute persisted_variable_name.
3 4 5 |
# File 'lib/edge-state-machine/machine.rb', line 3 def persisted_variable_name @persisted_variable_name end |
#states ⇒ Object
Returns the value of attribute states.
3 4 5 |
# File 'lib/edge-state-machine/machine.rb', line 3 def states @states end |
Instance Method Details
#create_scopes(bool = false) ⇒ Object
22 23 24 |
# File 'lib/edge-state-machine/machine.rb', line 22 def create_scopes(bool = false) @create_scopes = bool end |
#create_scopes? ⇒ Boolean
26 27 28 |
# File 'lib/edge-state-machine/machine.rb', line 26 def create_scopes? @create_scopes end |
#event(name, &transitions) ⇒ Object
36 37 38 |
# File 'lib/edge-state-machine/machine.rb', line 36 def event(name, &transitions) @events[name.to_sym] ||= EdgeStateMachine::Event.new(name, self, &transitions) end |
#initial_state(name) ⇒ Object
14 15 16 |
# File 'lib/edge-state-machine/machine.rb', line 14 def initial_state(name) @initial_state_name = name end |
#persisted_to(name) ⇒ Object
18 19 20 |
# File 'lib/edge-state-machine/machine.rb', line 18 def persisted_to(name) @persisted_variable_name = name end |
#state(name, &state) ⇒ Object
30 31 32 33 34 |
# File 'lib/edge-state-machine/machine.rb', line 30 def state(name, &state) state = EdgeStateMachine::State.new(name, &state) @initial_state_name ||= state.name @states[name.to_sym] = state end |