Class: Golem::Model::Transition

Inherits:
Object
  • Object
show all
Defined in:
lib/golem/model/transition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from, to, guards = [], callbacks = {}) ⇒ Transition

Returns a new instance of Transition.

Raises:

  • (ArgumentError)


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

#callbacksObject

Returns the value of attribute callbacks.



10
11
12
# File 'lib/golem/model/transition.rb', line 10

def callbacks
  @callbacks
end

#commentObject

Returns the value of attribute comment.



12
13
14
# File 'lib/golem/model/transition.rb', line 12

def comment
  @comment
end

#fromObject (readonly)

Returns the value of attribute from.



7
8
9
# File 'lib/golem/model/transition.rb', line 7

def from
  @from
end

#guardsObject

Returns the value of attribute guards.



9
10
11
# File 'lib/golem/model/transition.rb', line 9

def guards
  @guards
end

#toObject (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_sObject



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