Class: NxtStateMachine::Transition

Inherits:
Object
  • Object
show all
Includes:
Interface
Defined in:
lib/nxt_state_machine/transition.rb,
lib/nxt_state_machine/transition/interface.rb

Defined Under Namespace

Modules: Interface Classes: AroundCallbackChain, Factory, Proxy

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Interface

#id, #transitions_from_to?

Constructor Details

#initialize(name, event:, from:, to:, state_machine:, context:, set_state_method:, arguments:, options:, &block) ⇒ Transition

Returns a new instance of Transition.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/nxt_state_machine/transition.rb', line 5

def initialize(name, event:, from:, to:, state_machine:, context:, set_state_method:, arguments:, options:, &block)
  @name = name
  @event = event
  @from = state_machine.states.resolve!(from)
  @to = state_machine.states.resolve!(to)
  @state_machine = state_machine
  @set_state_method = set_state_method
  @context = context
  @block = block
  @arguments = arguments
  @options = options
  @result = nil
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



19
20
21
# File 'lib/nxt_state_machine/transition.rb', line 19

def arguments
  @arguments
end

#blockObject

Returns the value of attribute block.



19
20
21
# File 'lib/nxt_state_machine/transition.rb', line 19

def block
  @block
end

#eventObject (readonly)

Returns the value of attribute event.



19
20
21
# File 'lib/nxt_state_machine/transition.rb', line 19

def event
  @event
end

#fromObject (readonly)

Returns the value of attribute from.



19
20
21
# File 'lib/nxt_state_machine/transition.rb', line 19

def from
  @from
end

#nameObject (readonly)

Returns the value of attribute name.



19
20
21
# File 'lib/nxt_state_machine/transition.rb', line 19

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



19
20
21
# File 'lib/nxt_state_machine/transition.rb', line 19

def options
  @options
end

#resultObject

Returns the value of attribute result.



19
20
21
# File 'lib/nxt_state_machine/transition.rb', line 19

def result
  @result
end

#toObject (readonly)

Returns the value of attribute to.



19
20
21
# File 'lib/nxt_state_machine/transition.rb', line 19

def to
  @to
end

Instance Method Details

#execute(&block) ⇒ Object Also known as: with_around_callbacks

This must be used in set_state method to actually execute the transition within the around callback chain



36
37
38
# File 'lib/nxt_state_machine/transition.rb', line 36

def execute(&block)
  self.result = Transition::Proxy.new(event, state_machine,self, context).call(&block)
end

#run_after_callbacksObject



46
47
48
# File 'lib/nxt_state_machine/transition.rb', line 46

def run_after_callbacks
  state_machine.run_after_callbacks(self, context)
end

#run_before_callbacksObject



42
43
44
# File 'lib/nxt_state_machine/transition.rb', line 42

def run_before_callbacks
  state_machine.run_before_callbacks(self, context)
end

#run_success_callbacksObject



50
51
52
# File 'lib/nxt_state_machine/transition.rb', line 50

def run_success_callbacks
  state_machine.run_success_callbacks(self, context)
end

#triggerObject

This triggers the set state method



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/nxt_state_machine/transition.rb', line 22

def trigger
  Callable.new(
    state_machine.send(set_state_method)
  ).bind(
    context
  ).call(state_machine.target(context), self)
rescue StandardError => error
  callback = state_machine.find_error_callback(error, self)
  raise unless callback

  Callable.new(callback).bind(context).call(error, self)
end