Method: AASM::InstanceBase#events

Defined in:
lib/aasm/instance_base.rb

#events(options = {}, *args) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/aasm/instance_base.rb', line 60

def events(options={}, *args)
  state = options[:state] || current_state
  events = @instance.class.aasm(@name).events.select {|e| e.transitions_from_state?(state) }

  options[:reject] = Array(options[:reject])
  events.reject! { |e| options[:reject].include?(e.name) }

  if options.has_key?(:permitted)
    # filters the results of events_for_current_state so that only those that
    # are really currently possible (given transition guards) are shown.
    if options[:permitted]
      events.select! { |e| @instance.send("may_#{e.name}?", *args) }
    else
      events.select! { |e| !@instance.send("may_#{e.name}?", *args) }
    end
  end

  events
end