Class: EdgeStateMachine::Machine

Inherits:
Object
  • Object
show all
Defined in:
lib/edge-state-machine/machine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, name, &block) ⇒ Machine

Returns a new instance of Machine.



6
7
8
9
10
11
12
# File 'lib/edge-state-machine/machine.rb', line 6

def initialize(klass, name, &block)
  @klass = klass
  @name = name
  @states = Hash.new
  @events = Hash.new
  instance_eval(&block) if block_given?
end

Instance Attribute Details

#eventsObject

Returns the value of attribute events.



3
4
5
# File 'lib/edge-state-machine/machine.rb', line 3

def events
  @events
end

#initial_state_nameObject (readonly)

Returns the value of attribute initial_state_name.



4
5
6
# File 'lib/edge-state-machine/machine.rb', line 4

def initial_state_name
  @initial_state_name
end

#klassObject

Returns the value of attribute klass.



3
4
5
# File 'lib/edge-state-machine/machine.rb', line 3

def klass
  @klass
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/edge-state-machine/machine.rb', line 4

def name
  @name
end

#persisted_variable_nameObject

Returns the value of attribute persisted_variable_name.



3
4
5
# File 'lib/edge-state-machine/machine.rb', line 3

def persisted_variable_name
  @persisted_variable_name
end

#statesObject

Returns the value of attribute states.



3
4
5
# File 'lib/edge-state-machine/machine.rb', line 3

def states
  @states
end

Instance Method Details

#create_scopes(bool = false) ⇒ Object



22
23
24
# File 'lib/edge-state-machine/machine.rb', line 22

def create_scopes(bool = false)
  @create_scopes = bool
end

#create_scopes?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/edge-state-machine/machine.rb', line 26

def create_scopes?
  @create_scopes
end

#event(name, &transitions) ⇒ Object



36
37
38
# File 'lib/edge-state-machine/machine.rb', line 36

def event(name, &transitions)
  @events[name.to_sym] ||= EdgeStateMachine::Event.new(name, self, &transitions)
end

#initial_state(name) ⇒ Object



14
15
16
# File 'lib/edge-state-machine/machine.rb', line 14

def initial_state(name)
  @initial_state_name = name
end

#persisted_to(name) ⇒ Object



18
19
20
# File 'lib/edge-state-machine/machine.rb', line 18

def persisted_to(name)
  @persisted_variable_name = name
end

#state(name, &state) ⇒ Object



30
31
32
33
34
# File 'lib/edge-state-machine/machine.rb', line 30

def state(name, &state)
  state = EdgeStateMachine::State.new(name, &state)
  @initial_state_name ||= state.name
  @states[name.to_sym] = state
end