Class: Workflow::State

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/workflow/state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value, spec, meta = {}) ⇒ State

Returns a new instance of State.



9
10
11
# File 'lib/workflow/state.rb', line 9

def initialize(name, value, spec, meta = {})
  @name, @value, @spec, @events, @meta = name, value, spec, EventCollection.new, meta
end

Instance Attribute Details

#eventsObject

Returns the value of attribute events.



6
7
8
# File 'lib/workflow/state.rb', line 6

def events
  @events
end

#metaObject

Returns the value of attribute meta.



6
7
8
# File 'lib/workflow/state.rb', line 6

def meta
  @meta
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/workflow/state.rb', line 6

def name
  @name
end

#on_entryObject

Returns the value of attribute on_entry.



6
7
8
# File 'lib/workflow/state.rb', line 6

def on_entry
  @on_entry
end

#on_exitObject

Returns the value of attribute on_exit.



6
7
8
# File 'lib/workflow/state.rb', line 6

def on_exit
  @on_exit
end

#specObject (readonly)

Returns the value of attribute spec.



7
8
9
# File 'lib/workflow/state.rb', line 7

def spec
  @spec
end

#valueObject

Returns the value of attribute value.



6
7
8
# File 'lib/workflow/state.rb', line 6

def value
  @value
end

Instance Method Details

#<=>(other_state) ⇒ Object

Raises:

  • (ArgumentError)


29
30
31
32
33
# File 'lib/workflow/state.rb', line 29

def <=>(other_state)
  states = spec.states.keys
  raise ArgumentError, "state `#{other_state}' does not exist" unless states.include?(other_state.to_sym)
  states.index(self.to_sym) <=> states.index(other_state.to_sym)
end

#draw(graph) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/workflow/state.rb', line 13

def draw(graph)
  defaults = {
    :label => to_s,
    :width => '1',
    :height => '1',
    :shape => 'ellipse'
  }

  node = graph.add_nodes(to_s, defaults)

  # Add open arrow for initial state
  # graph.add_edge(graph.add_node('starting_state', :shape => 'point'), node) if initial?

  node
end

#to_sObject



35
36
37
# File 'lib/workflow/state.rb', line 35

def to_s
  "#{name}"
end

#to_symObject



39
40
41
# File 'lib/workflow/state.rb', line 39

def to_sym
  name.to_sym
end