Class: SimpleStateMachine::StateMachineDefinition

Inherits:
Object
  • Object
show all
Extended by:
Mountable
Includes:
Mountable::InstanceMethods, Tools::Graphviz, Tools::Inspector
Defined in:
lib/simple_state_machine/state_machine_definition.rb

Overview

Defines state machine transitions

Defined Under Namespace

Modules: Mountable

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mountable

event, events

Methods included from Tools::Inspector

#begin_states, #end_states, #states

Methods included from Tools::Graphviz

#google_chart_url, #to_graphviz_dot

Methods included from Mountable::InstanceMethods

#add_events

Instance Attribute Details

#decoratorObject



9
10
11
# File 'lib/simple_state_machine/state_machine_definition.rb', line 9

def decorator
  @decorator ||= decorator_class.new(@subject)
end

#decorator_classObject



13
14
15
# File 'lib/simple_state_machine/state_machine_definition.rb', line 13

def decorator_class
  @decorator_class ||= Decorator::Default
end

#default_error_stateObject



17
18
19
# File 'lib/simple_state_machine/state_machine_definition.rb', line 17

def default_error_state
  @default_error_state && @default_error_state.to_s
end

#state_methodObject



39
40
41
# File 'lib/simple_state_machine/state_machine_definition.rb', line 39

def state_method
  @state_method ||= :state
end

#subject=(value) ⇒ Object (writeonly)

Sets the attribute subject

Parameters:

  • value

    the value to set the attribute subject to.



6
7
8
# File 'lib/simple_state_machine/state_machine_definition.rb', line 6

def subject=(value)
  @subject = value
end

Instance Method Details

#add_transition(event_name, from, to) ⇒ Object



33
34
35
36
37
# File 'lib/simple_state_machine/state_machine_definition.rb', line 33

def add_transition event_name, from, to
  transition = Transition.new(event_name, from, to)
  transitions << transition
  decorator.decorate(transition)
end

#define_event(event_name, state_transitions) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/simple_state_machine/state_machine_definition.rb', line 25

def define_event event_name, state_transitions
  state_transitions.each do |froms, to|
    [froms].flatten.each do |from|
      add_transition(event_name, from, to)
    end
  end
end

#to_sObject

Human readable format: old_state.event! => new_state



44
45
46
# File 'lib/simple_state_machine/state_machine_definition.rb', line 44

def to_s
  transitions.map(&:to_s).join("\n")
end

#transitionsObject



21
22
23
# File 'lib/simple_state_machine/state_machine_definition.rb', line 21

def transitions
  @transitions ||= []
end