Class: AASM::SupportingClasses::StateTransition

Inherits:
Object
  • Object
show all
Defined in:
lib/alexrevin-aasm_numerical/state_transition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ StateTransition

Returns a new instance of StateTransition.



5
6
7
8
# File 'lib/alexrevin-aasm_numerical/state_transition.rb', line 5

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.



2
3
4
# File 'lib/alexrevin-aasm_numerical/state_transition.rb', line 2

def from
  @from
end

#optsObject (readonly) Also known as: options

Returns the value of attribute opts.



2
3
4
# File 'lib/alexrevin-aasm_numerical/state_transition.rb', line 2

def opts
  @opts
end

#toObject (readonly)

Returns the value of attribute to.



2
3
4
# File 'lib/alexrevin-aasm_numerical/state_transition.rb', line 2

def to
  @to
end

Instance Method Details

#==(obj) ⇒ Object



27
28
29
# File 'lib/alexrevin-aasm_numerical/state_transition.rb', line 27

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

#execute(obj, *args) ⇒ Object



21
22
23
24
25
# File 'lib/alexrevin-aasm_numerical/state_transition.rb', line 21

def execute(obj, *args)
  @on_transition.is_a?(Array) ?
          @on_transition.each {|ot| _execute(obj, ot, *args)} :
          _execute(obj, @on_transition, *args)
end

#from?(value) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/alexrevin-aasm_numerical/state_transition.rb', line 31

def from?(value)
  @from == value
end

#perform(obj, *args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/alexrevin-aasm_numerical/state_transition.rb', line 10

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