Class: AASM::SupportingClasses::StateTransition
- Inherits:
-
Object
- Object
- AASM::SupportingClasses::StateTransition
- Defined in:
- lib/aasm/state_transition.rb
Instance Attribute Summary collapse
-
#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
- #execute(obj, *args) ⇒ Object
- #from?(value) ⇒ Boolean
-
#initialize(opts) ⇒ StateTransition
constructor
A new instance of StateTransition.
- #perform(obj) ⇒ Object
Constructor Details
#initialize(opts) ⇒ StateTransition
Returns a new instance of StateTransition.
5 6 7 8 |
# File 'lib/aasm/state_transition.rb', line 5 def initialize(opts) @from, @to, @guard, @on_transition = opts[:from], opts[:to], opts[:guard], opts[:on_transition] @opts = opts end |
Instance Attribute Details
#from ⇒ Object (readonly)
Returns the value of attribute from.
2 3 4 |
# File 'lib/aasm/state_transition.rb', line 2 def from @from end |
#opts ⇒ Object (readonly) Also known as: options
Returns the value of attribute opts.
2 3 4 |
# File 'lib/aasm/state_transition.rb', line 2 def opts @opts end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
2 3 4 |
# File 'lib/aasm/state_transition.rb', line 2 def to @to end |
Instance Method Details
#==(obj) ⇒ Object
27 28 29 |
# File 'lib/aasm/state_transition.rb', line 27 def ==(obj) @from == obj.from && @to == obj.to end |
#execute(obj, *args) ⇒ Object
21 22 23 24 25 |
# File 'lib/aasm/state_transition.rb', line 21 def execute(obj, *args) @on_transition.is_a?(Array) ? @on_transition.each {|ot| _execute(obj, ot, *args)} : _execute(obj, @on_transition, *args) end |
#from?(value) ⇒ Boolean
31 32 33 |
# File 'lib/aasm/state_transition.rb', line 31 def from?(value) @from == value end |
#perform(obj) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/aasm/state_transition.rb', line 10 def perform(obj) case @guard when Symbol, String obj.send(@guard) when Proc @guard.call(obj) else true end end |