Class: ScottBarron::Acts::StateMachine::SupportingClasses::State

Inherits:
Object
  • Object
show all
Defined in:
lib/acts_as_state_machine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ State

Returns a new instance of State.



20
21
22
23
24
25
26
# File 'lib/acts_as_state_machine.rb', line 20

def initialize(name, options)
  @name  = name.to_sym
  @value = (options[:value] || @name).to_s
  @after = Array(options[:after])
  @enter = options[:enter] || NOOP
  @exit  = options[:exit] || NOOP
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



18
19
20
# File 'lib/acts_as_state_machine.rb', line 18

def name
  @name
end

#valueObject (readonly)

Returns the value of attribute value.



18
19
20
# File 'lib/acts_as_state_machine.rb', line 18

def value
  @value
end

Instance Method Details

#entered(record) ⇒ Object



32
33
34
# File 'lib/acts_as_state_machine.rb', line 32

def entered(record)
  @after.each { |action| record.send(:run_transition_action, action) }
end

#entering(record) ⇒ Object



28
29
30
# File 'lib/acts_as_state_machine.rb', line 28

def entering(record)
  record.send(:run_transition_action, @enter)
end

#exited(record) ⇒ Object



36
37
38
# File 'lib/acts_as_state_machine.rb', line 36

def exited(record)
  record.send(:run_transition_action, @exit)
end