Class: AASM::SupportingClasses::StateTransition
- Inherits:
-
Object
- Object
- AASM::SupportingClasses::StateTransition
- Defined in:
- lib/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
- #has_context?(context) ⇒ Boolean
-
#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/state_transition.rb', line 6 def initialize(opts) @from, @to, @guard, @on_transition, @context = opts[:from], opts[:to], opts[:guard], opts[:on_transition], opts[:context] @opts = opts end |
Instance Attribute Details
#from ⇒ Object (readonly)
Returns the value of attribute from.
4 5 6 |
# File 'lib/state_transition.rb', line 4 def from @from end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
4 5 6 |
# File 'lib/state_transition.rb', line 4 def opts @opts end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
4 5 6 |
# File 'lib/state_transition.rb', line 4 def to @to end |
Instance Method Details
#==(obj) ⇒ Object
31 32 33 |
# File 'lib/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/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 |
#has_context?(context) ⇒ Boolean
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/state_transition.rb', line 35 def has_context?(context) return true if context == :all case @context when Array return @context.include?(context) when Symbol return @context == context else true # if the transition doesn't belong to any context end end |
#perform(obj) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/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 |