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.
-
#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.
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 |
# File 'lib/aasm/core/transition.rb', line 8 def initialize(event, opts, &block) (opts, [:on_transition, :guard, :after], &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 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 @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 |
#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
37 38 39 |
# File 'lib/aasm/core/transition.rb', line 37 def ==(obj) @from == obj.from && @to == obj.to end |
#allowed?(obj, *args) ⇒ Boolean
27 28 29 30 |
# File 'lib/aasm/core/transition.rb', line 27 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
32 33 34 35 |
# File 'lib/aasm/core/transition.rb', line 32 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
41 42 43 |
# File 'lib/aasm/core/transition.rb', line 41 def from?(value) @from == value end |