Class: AASM::Core::Transition
- Inherits:
-
Object
- Object
- AASM::Core::Transition
- Includes:
- DslHelper
- Defined in:
- lib/aasm/core/transition.rb
Instance Attribute Summary collapse
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#failures ⇒ Object
readonly
Returns the value of attribute failures.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#opts ⇒ Object
(also: #options)
readonly
Returns the value of attribute opts.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Instance Method Summary collapse
- #==(obj) ⇒ Object
- #allowed?(obj, *args) ⇒ Boolean
- #execute(obj, *args) ⇒ Object
- #from?(value) ⇒ Boolean
-
#initialize(event, opts, &block) ⇒ Transition
constructor
A new instance of Transition.
- #invoke_success_callbacks(obj, *args) ⇒ Object
Methods included from DslHelper
Constructor Details
#initialize(event, opts, &block) ⇒ Transition
Returns a new instance of Transition.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/aasm/core/transition.rb', line 8 def initialize(event, opts, &block) (opts, [:on_transition, :guard, :after, :success], &block) if block @event = event @from = opts[:from] @to = opts[:to] @guards = Array(opts[:guards]) + Array(opts[:guard]) + Array(opts[:if]) @unless = Array(opts[:unless]) #TODO: This could use a better name @failures = [] if opts[:on_transition] warn '[DEPRECATION] :on_transition is deprecated, use :after instead' opts[:after] = Array(opts[:after]) + Array(opts[:on_transition]) end @after = Array(opts[:after]) @after = @after[0] if @after.size == 1 @success = Array(opts[:success]) @success = @success[0] if @success.size == 1 @opts = opts end |
Instance Attribute Details
#event ⇒ Object (readonly)
Returns the value of attribute event.
5 6 7 |
# File 'lib/aasm/core/transition.rb', line 5 def event @event end |
#failures ⇒ Object (readonly)
Returns the value of attribute failures.
5 6 7 |
# File 'lib/aasm/core/transition.rb', line 5 def failures @failures end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
5 6 7 |
# File 'lib/aasm/core/transition.rb', line 5 def from @from end |
#opts ⇒ Object (readonly) Also known as: options
Returns the value of attribute opts.
5 6 7 |
# File 'lib/aasm/core/transition.rb', line 5 def opts @opts end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
5 6 7 |
# File 'lib/aasm/core/transition.rb', line 5 def to @to end |
Instance Method Details
#==(obj) ⇒ Object
41 42 43 |
# File 'lib/aasm/core/transition.rb', line 41 def ==(obj) @from == obj.from && @to == obj.to end |
#allowed?(obj, *args) ⇒ Boolean
31 32 33 34 |
# File 'lib/aasm/core/transition.rb', line 31 def allowed?(obj, *args) invoke_callbacks_compatible_with_guard(@guards, obj, args, :guard => true) && invoke_callbacks_compatible_with_guard(@unless, obj, args, :unless => true) end |
#execute(obj, *args) ⇒ Object
36 37 38 39 |
# File 'lib/aasm/core/transition.rb', line 36 def execute(obj, *args) invoke_callbacks_compatible_with_guard(event.state_machine.global_callbacks[:after_all_transitions], obj, args) invoke_callbacks_compatible_with_guard(@after, obj, args) end |
#from?(value) ⇒ Boolean
45 46 47 |
# File 'lib/aasm/core/transition.rb', line 45 def from?(value) @from == value end |
#invoke_success_callbacks(obj, *args) ⇒ Object
49 50 51 |
# File 'lib/aasm/core/transition.rb', line 49 def invoke_success_callbacks(obj, *args) _fire_callbacks(@success, obj, args) end |