Class: Mongoid::StateMachine::SupportingClasses::State

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ State

Returns a new instance of State.



22
23
24
25
26
27
28
# File 'lib/mongoid/state_machine.rb', line 22

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.



20
21
22
# File 'lib/mongoid/state_machine.rb', line 20

def name
  @name
end

#valueObject (readonly)

Returns the value of attribute value.



20
21
22
# File 'lib/mongoid/state_machine.rb', line 20

def value
  @value
end

Instance Method Details

#entered(record) ⇒ Object



34
35
36
# File 'lib/mongoid/state_machine.rb', line 34

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

#entering(record) ⇒ Object



30
31
32
# File 'lib/mongoid/state_machine.rb', line 30

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

#exited(record) ⇒ Object



38
39
40
# File 'lib/mongoid/state_machine.rb', line 38

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