Module: SimplerStateMachine::ClassMethods

Defined in:
lib/simpler_state_machine/simple_state_machine.rb

Instance Method Summary collapse

Instance Method Details

#inherited(child) ⇒ Object

When inherited - duplicate the state machine from the parent class and allow the extend it



23
24
25
26
27
28
29
# File 'lib/simpler_state_machine/simple_state_machine.rb', line 23

def inherited(child)
  me = self
  child.class_eval do
    @sm = me.state_machine.clone
    @sm.clazz = self
  end
end

#state_machine(&block) ⇒ Object

Create or return a state machine



32
33
34
35
36
37
38
39
# File 'lib/simpler_state_machine/simple_state_machine.rb', line 32

def state_machine(&block)
  return @sm if !(@sm.nil?) && !(block_given?)
  @sm ||= SimplerStateMachine::Base.new(self)
  @sm.instance_eval(&block) if block_given?
  @sm.enumize!
  self.const_set(@sm.states_constant_name,@sm.states).freeze
  return @sm
end