Class: NxtStateMachine::Transition
- Inherits:
-
Object
- Object
- NxtStateMachine::Transition
- 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
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Instance Method Summary collapse
-
#execute(&block) ⇒ Object
(also: #with_around_callbacks)
This must be used in set_state method to actually execute the transition within the around callback chain.
-
#initialize(name, event:, from:, to:, state_machine:, context:, set_state_method:, arguments:, options:, &block) ⇒ Transition
constructor
A new instance of Transition.
- #run_after_callbacks ⇒ Object
- #run_before_callbacks ⇒ Object
- #run_success_callbacks ⇒ Object
-
#trigger ⇒ Object
This triggers the set state method.
Methods included from Interface
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 = @result = nil end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
19 20 21 |
# File 'lib/nxt_state_machine/transition.rb', line 19 def arguments @arguments end |
#block ⇒ Object
Returns the value of attribute block.
19 20 21 |
# File 'lib/nxt_state_machine/transition.rb', line 19 def block @block end |
#event ⇒ Object (readonly)
Returns the value of attribute event.
19 20 21 |
# File 'lib/nxt_state_machine/transition.rb', line 19 def event @event end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
19 20 21 |
# File 'lib/nxt_state_machine/transition.rb', line 19 def from @from end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/nxt_state_machine/transition.rb', line 19 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
19 20 21 |
# File 'lib/nxt_state_machine/transition.rb', line 19 def @options end |
#result ⇒ Object
Returns the value of attribute result.
19 20 21 |
# File 'lib/nxt_state_machine/transition.rb', line 19 def result @result end |
#to ⇒ Object (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_callbacks ⇒ Object
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_callbacks ⇒ Object
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_callbacks ⇒ Object
50 51 52 |
# File 'lib/nxt_state_machine/transition.rb', line 50 def run_success_callbacks state_machine.run_success_callbacks(self, context) end |
#trigger ⇒ Object
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 |