Module: Opensteam::StateMachine::ClassMethods
- Defined in:
- lib/opensteam/state_machine.rb,
lib/opensteam/state_machine.rb
Instance Method Summary collapse
- #get_observer ⇒ Object
- #initial_state(state) ⇒ Object
-
#notify(assoc) ⇒ Object
notify association on state-change calls the observers of the association.
-
#observe(&block) ⇒ Object
observe state-changes -> calls given block after change_state.
Instance Method Details
#get_observer ⇒ Object
38 |
# File 'lib/opensteam/state_machine.rb', line 38 def get_observer ; @@observer ||= [] ; end |
#initial_state(state) ⇒ Object
40 41 42 43 |
# File 'lib/opensteam/state_machine.rb', line 40 def initial_state( state ) self.initialstate = state after_create { |record| record.state = state } end |
#notify(assoc) ⇒ Object
notify association on state-change calls the observers of the association
52 53 54 55 56 |
# File 'lib/opensteam/state_machine.rb', line 52 def notify(assoc) self.observers << Opensteam::StateMachine::Observer.new( self ) do |record| record.send( assoc ).class.observers.each { |o| o.exc( record.send( assoc ) ) } end end |
#observe(&block) ⇒ Object
observe state-changes -> calls given block after change_state
46 47 48 |
# File 'lib/opensteam/state_machine.rb', line 46 def observe( &block ) observers << Opensteam::StateMachine::Observer.new( self, &block ) end |