Module: StateFu::Interface::InstanceMethods
- Defined in:
- lib/interface.rb
Overview
These methods grant access to StateFu::Binding objects, which are bundles of context encapsulating a StateFu::Machine, an instance of a class, and its current state in the machine.
Instance Method Summary (collapse)
- - (Object) current_state(name = DEFAULT)
- - (Object) next!(name = DEFAULT, *args, &block) (also: #next_state!, #fire_next_transition!)
-
- (Object) state_fu!
Instantiate bindings for all machines, which ensures that persistence fields are intialized and event methods defined.
-
- (Object) state_fu_binding(name = DEFAULT)
(also: #state_fu)
A StateFu::Binding comes into being when it is first referenced.
- - (Object) state_fu_bindings
Instance Method Details
- (Object) current_state(name = DEFAULT)
107 108 109 |
# File 'lib/interface.rb', line 107 def current_state( name = DEFAULT ) state_fu_binding(name).current_state end |
- (Object) next!(name = DEFAULT, *args, &block) Also known as: next_state!, fire_next_transition!
111 112 113 |
# File 'lib/interface.rb', line 111 def next!(name = DEFAULT, *args, &block ) state_fu_binding(name).next! *args, &block end |
- (Object) state_fu!
Instantiate bindings for all machines, which ensures that persistence fields are intialized and event methods defined. It's useful to call this before_create w/ ActiveRecord classes, as this will cause the database field to be populated with the default state name.
123 124 125 126 |
# File 'lib/interface.rb', line 123 def state_fu! MethodFactory.define_singleton_method(self, :initialize_state_fu!) { true } self.class.state_fu_machines.keys.map { |n| state_fu_binding( n ) } end |
- (Object) state_fu_binding(name = DEFAULT) Also known as: state_fu
A StateFu::Binding comes into being when it is first referenced.
This is the accessor method through which an object instance (or developer) can access a StateFu::Machine, the object's current state, the methods which trigger event transitions, etc.
98 99 100 101 102 103 104 |
# File 'lib/interface.rb', line 98 def state_fu_binding(name = DEFAULT) name = name.to_sym if machine = self.class.state_fu_machines[name] state_fu_bindings[name] ||= StateFu::Binding.new( machine, self, name ) else raise ArgumentError.new("No state machine called #{name} for #{self.class} #{self}") end end |
- (Object) state_fu_bindings
88 89 90 |
# File 'lib/interface.rb', line 88 def state_fu_bindings @_state_fu_bindings ||= {} end |