Class: ScottBarron::Acts::StateMachine::SupportingClasses::Event

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, opts, transition_table, &block) ⇒ Event

Returns a new instance of Event.



81
82
83
84
85
86
87
88
89
# File 'lib/acts_as_state_machine.rb', line 81

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.



77
78
79
# File 'lib/acts_as_state_machine.rb', line 77

def name
  @name
end

#optsObject (readonly)

Returns the value of attribute opts.



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

def opts
  @opts
end

#transitions(trans_opts) ⇒ Object (readonly)

Returns the value of attribute transitions.



78
79
80
# File 'lib/acts_as_state_machine.rb', line 78

def transitions
  @transitions
end

Instance Method Details

#fire(record) ⇒ Object



95
96
97
98
99
# File 'lib/acts_as_state_machine.rb', line 95

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

#next_states(record) ⇒ Object



91
92
93
# File 'lib/acts_as_state_machine.rb', line 91

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