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, spec, meta = {}) ⇒ State

Returns a new instance of State.



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

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

Instance Attribute Details

#eventsObject

Returns the value of attribute events.



3
4
5
# File 'lib/workflow/state.rb', line 3

def events
  @events
end

#metaObject

Returns the value of attribute meta.



3
4
5
# File 'lib/workflow/state.rb', line 3

def meta
  @meta
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/workflow/state.rb', line 3

def name
  @name
end

#on_entryObject

Returns the value of attribute on_entry.



3
4
5
# File 'lib/workflow/state.rb', line 3

def on_entry
  @on_entry
end

#on_exitObject

Returns the value of attribute on_exit.



3
4
5
# File 'lib/workflow/state.rb', line 3

def on_exit
  @on_exit
end

#specObject (readonly)

Returns the value of attribute spec.



4
5
6
# File 'lib/workflow/state.rb', line 4

def spec
  @spec
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



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/workflow/state.rb', line 10

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

  node = graph.add_nodes(to_s, defaults.merge(meta))

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

  node
end

#to_sObject



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

def to_s
  "#{name}"
end

#to_symObject



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

def to_sym
  name.to_sym
end