Class: Mongoid::StateMachine::SupportingClasses::Event

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, opts, transition_table, &block) ⇒ Event

Returns a new instance of Event.



83
84
85
86
87
88
89
90
91
# File 'lib/mongoid/state_machine.rb', line 83

def initialize(name, opts, transition_table, &block)
  @name = name.to_sym
  @transitions = transition_table[@name] = []
  instance_eval(&block) if block
  @opts = opts
  @opts.freeze
  @transitions.freeze
  freeze
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



79
80
81
# File 'lib/mongoid/state_machine.rb', line 79

def name
  @name
end

#optsObject (readonly)

Returns the value of attribute opts.



81
82
83
# File 'lib/mongoid/state_machine.rb', line 81

def opts
  @opts
end

#transitions(trans_opts) ⇒ Object (readonly)

Returns the value of attribute transitions.



80
81
82
# File 'lib/mongoid/state_machine.rb', line 80

def transitions
  @transitions
end

Instance Method Details

#fire(record) ⇒ Object



97
98
99
100
101
# File 'lib/mongoid/state_machine.rb', line 97

def fire(record)
  next_states(record).each do |transition|
    break true if transition.perform(record)
  end
end

#next_states(record) ⇒ Object



93
94
95
# File 'lib/mongoid/state_machine.rb', line 93

def next_states(record)
  @transitions.select { |t| t.from == record.current_state.to_s }
end