Class: AASM::SupportingClasses::Event

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Event

Returns a new instance of Event.



8
9
10
11
12
# File 'lib/event.rb', line 8

def initialize(name, &block)
  @name = name
  @transitions = []
  instance_eval(&block) if block
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/event.rb', line 6

def name
  @name
end

Instance Method Details

#fire(obj) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/event.rb', line 14

def fire(obj)
  transitions = @transitions.select { |t| t.from == obj.aasm_current_state }
  raise AASM::InvalidTransition if transitions.size == 0

  next_state = nil
  transitions.each do |transition|
    if transition.perform(obj)
      next_state = transition.to
      break
    end
  end
  next_state
end

#transitions_from_state?(state) ⇒ Boolean

Returns:

  • (Boolean)


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

def transitions_from_state?(state)
  @transitions.any? { |t| t.from == state }
end