Class: ExMachina::Event::Transition

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Transition

Returns a new instance of Transition.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/ex_machina/event/transition.rb', line 8

def initialize(**options)
  @from    = Array(options.fetch(:from)).map { |status| normalize(status) }
  @to      = normalize(options.fetch(:to))

  # optional args
  @do_if      = options[:if]
  @do_unless  = options[:unless]
  @do_before  = options[:before]
  @do_after   = options[:after]
  @do_success = options[:success]
  @do_failure = options[:failure]
  @do_error   = options[:error]
end

Instance Attribute Details

#do_afterObject (readonly)

Returns the value of attribute do_after.



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

def do_after
  @do_after
end

#do_beforeObject (readonly)

Returns the value of attribute do_before.



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

def do_before
  @do_before
end

#do_errorObject (readonly)

Returns the value of attribute do_error.



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

def do_error
  @do_error
end

#do_failureObject (readonly)

Returns the value of attribute do_failure.



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

def do_failure
  @do_failure
end

#do_ifObject (readonly)

Returns the value of attribute do_if.



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

def do_if
  @do_if
end

#do_successObject (readonly)

Returns the value of attribute do_success.



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

def do_success
  @do_success
end

#do_unlessObject (readonly)

Returns the value of attribute do_unless.



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

def do_unless
  @do_unless
end

#fromObject (readonly)

Returns the value of attribute from.



5
6
7
# File 'lib/ex_machina/event/transition.rb', line 5

def from
  @from
end

#toObject (readonly)

Returns the value of attribute to.



5
6
7
# File 'lib/ex_machina/event/transition.rb', line 5

def to
  @to
end

Instance Method Details

#conditional?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/ex_machina/event/transition.rb', line 30

def conditional?
  !do_if.nil? || !do_unless.nil?
end

#from?(status) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/ex_machina/event/transition.rb', line 22

def from?(status)
  from.include?(normalize(status))
end

#to?(status) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/ex_machina/event/transition.rb', line 26

def to?(status)
  Array(to).include?(normalize(status))
end