Module: CanHasState::Machine::ClassMethods
- Defined in:
- lib/can_has_state/machine.rb
Instance Method Summary collapse
Instance Method Details
#extend_state_machine(column, &block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/can_has_state/machine.rb', line 21 def extend_state_machine(column, &block) column = column.to_sym sm = state_machines[column] || raise(ArgumentError, "Unknown state machine #{column}") # handle when sm is inherited from a parent class if sm.parent_context != self sm = sm.dup sm.parent_context = self self.state_machines = state_machines.merge(column => sm) end sm.extend_machine(&block) column end |
#state_machine(column, &block) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/can_has_state/machine.rb', line 7 def state_machine(column, &block) column = column.to_sym raise(ArgumentError, "State machine for #{column} already exists") if state_machines.key?(column) d = Definition.new(column, self, &block) define_method "allow_#{column}?" do |to| state_machine_allow?(column.to_sym, to.to_s) end self.state_machines = state_machines.merge(column => d) column end |