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.
-
#initialize_copy(orig) ⇒ Object
called internally by Ruby 1.9 after clone().
- #invoke_success_callbacks(obj, *args) ⇒ Object
Methods included from DslHelper
Constructor Details
#initialize(event, opts, &block) ⇒ Transition
Returns a new instance of Transition.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/aasm/core/transition.rb', line 10 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.
7 8 9 |
# File 'lib/aasm/core/transition.rb', line 7 def event @event end |
#failures ⇒ Object (readonly)
Returns the value of attribute failures.
7 8 9 |
# File 'lib/aasm/core/transition.rb', line 7 def failures @failures end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
7 8 9 |
# File 'lib/aasm/core/transition.rb', line 7 def from @from end |
#opts ⇒ Object (readonly) Also known as: options
Returns the value of attribute opts.
7 8 9 |
# File 'lib/aasm/core/transition.rb', line 7 def opts @opts end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
7 8 9 |
# File 'lib/aasm/core/transition.rb', line 7 def to @to end |
Instance Method Details
#==(obj) ⇒ Object
52 53 54 |
# File 'lib/aasm/core/transition.rb', line 52 def ==(obj) @from == obj.from && @to == obj.to end |
#allowed?(obj, *args) ⇒ Boolean
42 43 44 45 |
# File 'lib/aasm/core/transition.rb', line 42 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
47 48 49 50 |
# File 'lib/aasm/core/transition.rb', line 47 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
56 57 58 |
# File 'lib/aasm/core/transition.rb', line 56 def from?(value) @from == value end |
#initialize_copy(orig) ⇒ Object
called internally by Ruby 1.9 after clone()
34 35 36 37 38 39 40 |
# File 'lib/aasm/core/transition.rb', line 34 def initialize_copy(orig) super @guards = @guards.dup @unless = @unless.dup @opts = {} orig.opts.each_pair { |name, setting| @opts[name] = setting.is_a?(Hash) || setting.is_a?(Array) ? setting.dup : setting } end |
#invoke_success_callbacks(obj, *args) ⇒ Object
60 61 62 |
# File 'lib/aasm/core/transition.rb', line 60 def invoke_success_callbacks(obj, *args) _fire_callbacks(@success, obj, args) end |