Class: Workflow::State

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of State.



88
89
90
# File 'lib/workflow.rb', line 88

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

Instance Attribute Details

#eventsObject

Returns the value of attribute events.



85
86
87
# File 'lib/workflow.rb', line 85

def events
  @events
end

#metaObject

Returns the value of attribute meta.



85
86
87
# File 'lib/workflow.rb', line 85

def meta
  @meta
end

#nameObject

Returns the value of attribute name.



85
86
87
# File 'lib/workflow.rb', line 85

def name
  @name
end

#on_entryObject

Returns the value of attribute on_entry.



85
86
87
# File 'lib/workflow.rb', line 85

def on_entry
  @on_entry
end

#on_exitObject

Returns the value of attribute on_exit.



85
86
87
# File 'lib/workflow.rb', line 85

def on_exit
  @on_exit
end

#specObject (readonly)

Returns the value of attribute spec.



86
87
88
# File 'lib/workflow.rb', line 86

def spec
  @spec
end

Instance Method Details

#<=>(other_state) ⇒ Object

Raises:

  • (ArgumentError)


95
96
97
98
99
100
101
102
103
104
105
# File 'lib/workflow.rb', line 95

def <=>(other_state)
  states = spec.states.keys
  raise ArgumentError, "state `#{other_state}' does not exist" unless other_state.in? states
  if states.index(self.to_sym) < states.index(other_state.to_sym)
    -1
  elsif states.index(self.to_sym) > states.index(other_state.to_sym)
    1
  else
    0
  end
end

#to_sObject



108
109
110
# File 'lib/workflow.rb', line 108

def to_s
  "#{name}"
end

#to_symObject



112
113
114
# File 'lib/workflow.rb', line 112

def to_sym
  name.to_sym
end