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, options = {}, &block) ⇒ Event



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

def initialize(name, options = {}, &block)
  @name = name
  @success = options[:success]
  @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

#successObject (readonly)

Returns the value of attribute success.



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

def success
  @success
end

Instance Method Details

#fire(obj) ⇒ Object



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

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



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

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