Module: Transitionable::ClassMethods
- Defined in:
- lib/transitionable.rb
Instance Attribute Summary collapse
-
#state_machines ⇒ Object
Returns the value of attribute state_machines.
Instance Method Summary collapse
-
#transition(name, states = self::STATES, transitions = self::TRANSITIONS) ⇒ Object
This assumes states is a hash.
Instance Attribute Details
#state_machines ⇒ Object
Returns the value of attribute state_machines.
19 20 21 |
# File 'lib/transitionable.rb', line 19 def state_machines @state_machines end |
Instance Method Details
#transition(name, states = self::STATES, transitions = self::TRANSITIONS) ⇒ Object
This assumes states is a hash
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/transitionable.rb', line 22 def transition(name, states = self::STATES, transitions = self::TRANSITIONS) self.state_machines ||= {} self.state_machines[name] = { states: states.values, transitions: transitions } self.state_machines[name][:states].each do |this_state| method_name = "#{this_state}?".to_sym raise 'Method already defined' if self.instance_methods(false).include?(method_name) define_method method_name do current_state_based_on(this_state) == this_state end end end |