Class: Workflow::TransitionContext
- Inherits:
-
Object
- Object
- Workflow::TransitionContext
- Defined in:
- lib/workflow/transition_context.rb
Overview
During transitions, an instance of this class can be found
on the object as transition_context.
Contains metadata related to the current transition underway.
== To name parameters:
During workflow definition, do the following:
before_transition :transition_handler
def transition_handler
transition_context.name1 # will equal 1
transition_context.name2 # will equal 2
transition_context.name3 # will equal 3
end
workflow do
event_args :name1, :name2, :name3
state :foo do
event :bar, transitions_to: :bax
end
end
Then later call:
my_obj.submit! 1, 2, 3
The entire list of passed parameters will still be available on +event_args+. If you pass fewer parameters, the later ones will simply be nil.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#event_args ⇒ Object
readonly
Returns the value of attribute event_args.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#named_arguments ⇒ Object
readonly
Returns the value of attribute named_arguments.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Instance Method Summary collapse
-
#initialize(from:, to:, event:, event_args:, **args) ⇒ TransitionContext
constructor
A new instance of TransitionContext.
- #method_missing(method, *args) ⇒ Object
- #respond_to_missing?(method, _include_private = false) ⇒ Boolean
- #values ⇒ Object
Constructor Details
#initialize(from:, to:, event:, event_args:, **args) ⇒ TransitionContext
Returns a new instance of TransitionContext.
34 35 36 37 38 39 40 41 |
# File 'lib/workflow/transition_context.rb', line 34 def initialize(from:, to:, event:, event_args:, **args) @from = from @to = to @event = event @event_args = event_args @attributes = args[:attributes] || {} @named_arguments = (args[:named_arguments] || []).zip(event_args).to_h end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/workflow/transition_context.rb', line 51 def method_missing(method, *args) if named_arguments.key?(method) named_arguments[method] else super end end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
33 34 35 |
# File 'lib/workflow/transition_context.rb', line 33 def attributes @attributes end |
#event ⇒ Object (readonly)
Returns the value of attribute event.
33 34 35 |
# File 'lib/workflow/transition_context.rb', line 33 def event @event end |
#event_args ⇒ Object (readonly)
Returns the value of attribute event_args.
33 34 35 |
# File 'lib/workflow/transition_context.rb', line 33 def event_args @event_args end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
33 34 35 |
# File 'lib/workflow/transition_context.rb', line 33 def from @from end |
#named_arguments ⇒ Object (readonly)
Returns the value of attribute named_arguments.
33 34 35 |
# File 'lib/workflow/transition_context.rb', line 33 def named_arguments @named_arguments end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
33 34 35 |
# File 'lib/workflow/transition_context.rb', line 33 def to @to end |
Instance Method Details
#respond_to_missing?(method, _include_private = false) ⇒ Boolean
47 48 49 |
# File 'lib/workflow/transition_context.rb', line 47 def respond_to_missing?(method, _include_private = false) named_arguments.key?(method) || super end |
#values ⇒ Object
43 44 45 |
# File 'lib/workflow/transition_context.rb', line 43 def values [from, to, event, event_args.dup, attributes.dup] end |