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
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
-
#initialize(opts) ⇒ StateTransition
constructor
A new instance of StateTransition.
- #perform(obj) ⇒ Object
Constructor Details
#initialize(opts) ⇒ StateTransition
Returns a new instance of StateTransition.
6 7 8 9 |
# File 'lib/aasm/state_transition.rb', line 6 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.
4 5 6 |
# File 'lib/aasm/state_transition.rb', line 4 def from @from end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
4 5 6 |
# File 'lib/aasm/state_transition.rb', line 4 def opts @opts end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
4 5 6 |
# File 'lib/aasm/state_transition.rb', line 4 def to @to end |
Instance Method Details
#==(obj) ⇒ Object
31 32 33 |
# File 'lib/aasm/state_transition.rb', line 31 def ==(obj) @from == obj.from && @to == obj.to end |
#execute(obj, *args) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/aasm/state_transition.rb', line 22 def execute(obj, *args) case @on_transition when Symbol, String obj.send(@on_transition, *args) when Proc @on_transition.call(obj, *args) end end |
#perform(obj) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/aasm/state_transition.rb', line 11 def perform(obj) case @guard when Symbol, String obj.send(@guard) when Proc @guard.call(obj) else true end end |