Class: Golem::Model::Transition
- Inherits:
-
Object
- Object
- Golem::Model::Transition
- Defined in:
- lib/golem/model/transition.rb
Instance Attribute Summary collapse
-
#callbacks ⇒ Object
Returns the value of attribute callbacks.
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#guards ⇒ Object
Returns the value of attribute guards.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Instance Method Summary collapse
-
#initialize(from, to, guards = [], callbacks = {}) ⇒ Transition
constructor
A new instance of Transition.
- #to_s ⇒ Object
Constructor Details
#initialize(from, to, guards = [], callbacks = {}) ⇒ Transition
Returns a new instance of Transition.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/golem/model/transition.rb', line 14 def initialize(from, to, guards = [], callbacks = {}) @from = from @to = to raise ArgumentError, "'guards' must be an Enumerable collection of Golem::Model::Conditions but is #{guards.inspect}" unless guards.blank? || (guards.kind_of?(Enumerable) && guards.all?{|g| g.kind_of?(Golem::Model::Condition)}) @guards = guards raise ArgumentError, "'callbacks' must be a Hash of Golem::Model::Callbacks but is #{callbacks.inspect}" unless callbacks.blank? || (callbacks.kind_of?(Hash) && callbacks.all?{|k, c| c.kind_of?(Golem::Model::Callback)}) # only the :on_transition callback is currently implemented, but using a Hash of callbacks here leaves open # the possibility of other callbacks (e.g. :on_start, :on_finish, etc.) @callbacks = callbacks end |
Instance Attribute Details
#callbacks ⇒ Object
Returns the value of attribute callbacks.
10 11 12 |
# File 'lib/golem/model/transition.rb', line 10 def callbacks @callbacks end |
#comment ⇒ Object
Returns the value of attribute comment.
12 13 14 |
# File 'lib/golem/model/transition.rb', line 12 def comment @comment end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
7 8 9 |
# File 'lib/golem/model/transition.rb', line 7 def from @from end |
#guards ⇒ Object
Returns the value of attribute guards.
9 10 11 |
# File 'lib/golem/model/transition.rb', line 9 def guards @guards end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
8 9 10 |
# File 'lib/golem/model/transition.rb', line 8 def to @to end |
Instance Method Details
#to_s ⇒ Object
31 32 33 34 35 36 |
# File 'lib/golem/model/transition.rb', line 31 def to_s s ="Transition from #{from} to #{to}" s << " [#{guards.collect{|g| g.to_s}.join(" and ")}]" unless guards.empty? s << " / #{callbacks.collect{|k,v| v.to_s}.join(",")}" unless callbacks.blank? || callbacks.values.all?{|v| v.blank?} return s end |