Class: AASM::SupportingClasses::StateTransition

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ StateTransition

Returns a new instance of StateTransition.



6
7
8
9
# File 'lib/aasm/state_transition.rb', line 6

def initialize(opts)
  @from, @to, @guard, @on_transition = opts[:from], opts[:to], opts[:guard], opts[:on_transition]
  @opts = opts
end

Instance Attribute Details

#fromObject (readonly)

Returns the value of attribute from.



4
5
6
# File 'lib/aasm/state_transition.rb', line 4

def from
  @from
end

#optsObject (readonly)

Returns the value of attribute opts.



4
5
6
# File 'lib/aasm/state_transition.rb', line 4

def opts
  @opts
end

#toObject (readonly)

Returns the value of attribute to.



4
5
6
# File 'lib/aasm/state_transition.rb', line 4

def to
  @to
end

Instance Method Details

#==(obj) ⇒ Object



31
32
33
# File 'lib/aasm/state_transition.rb', line 31

def ==(obj)
  @from == obj.from && @to == obj.to
end

#execute(obj, *args) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/aasm/state_transition.rb', line 22

def execute(obj, *args)
  case @on_transition
  when Symbol, String
    obj.send(@on_transition, *args)
  when Proc
    @on_transition.call(obj, *args)
  end
end

#perform(obj) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/aasm/state_transition.rb', line 11

def perform(obj)
  case @guard
  when Symbol, String
    obj.send(@guard)
  when Proc
    @guard.call(obj)
  else
    true
  end
end