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:, attributes:, named_arguments: []) ⇒ TransitionContext
constructor
A new instance of TransitionContext.
- #method_missing(method, *args) ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(from:, to:, event:, event_args:, attributes:, named_arguments: []) ⇒ TransitionContext
Returns a new instance of TransitionContext.
33 34 35 36 37 38 39 40 |
# File 'lib/workflow/transition_context.rb', line 33 def initialize(from:, to:, event:, event_args:, attributes:, named_arguments: []) @from = from @to = to @event = event @event_args = event_args @attributes = attributes @named_arguments = (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
46 47 48 49 50 51 52 |
# File 'lib/workflow/transition_context.rb', line 46 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.
32 33 34 |
# File 'lib/workflow/transition_context.rb', line 32 def attributes @attributes end |
#event ⇒ Object (readonly)
Returns the value of attribute event.
32 33 34 |
# File 'lib/workflow/transition_context.rb', line 32 def event @event end |
#event_args ⇒ Object (readonly)
Returns the value of attribute event_args.
32 33 34 |
# File 'lib/workflow/transition_context.rb', line 32 def event_args @event_args end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
32 33 34 |
# File 'lib/workflow/transition_context.rb', line 32 def from @from end |
#named_arguments ⇒ Object (readonly)
Returns the value of attribute named_arguments.
32 33 34 |
# File 'lib/workflow/transition_context.rb', line 32 def named_arguments @named_arguments end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
32 33 34 |
# File 'lib/workflow/transition_context.rb', line 32 def to @to end |
Instance Method Details
#values ⇒ Object
42 43 44 |
# File 'lib/workflow/transition_context.rb', line 42 def values [from, to, event, event_args] end |