Class: RMachine::StateTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/r_machine/state_template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStateTemplate

Returns a new instance of StateTemplate.



5
6
7
8
# File 'lib/r_machine/state_template.rb', line 5

def initialize
  @state_value = nil
  @events_by_name = {}
end

Instance Attribute Details

#events_by_nameObject (readonly)

Returns the value of attribute events_by_name.



3
4
5
# File 'lib/r_machine/state_template.rb', line 3

def events_by_name
  @events_by_name
end

#state_field_nameObject (readonly)

Returns the value of attribute state_field_name.



3
4
5
# File 'lib/r_machine/state_template.rb', line 3

def state_field_name
  @state_field_name
end

Instance Method Details

#field=(field_name) ⇒ Object



22
23
24
# File 'lib/r_machine/state_template.rb', line 22

def field=(field_name)
  @state_field_name = field_name
end

#find_event(name) ⇒ Object



14
15
16
# File 'lib/r_machine/state_template.rb', line 14

def find_event(name)
  events_by_name[name]
end

#initial=(initial_status) ⇒ Object



26
27
28
# File 'lib/r_machine/state_template.rb', line 26

def initial=(initial_status)
  @state_value = initial_status
end

#on(event_name) {|event| ... } ⇒ Object

Yields:

  • (event)


30
31
32
33
34
# File 'lib/r_machine/state_template.rb', line 30

def on(event_name)
  event = Event.new(event_name)
  events_by_name[event_name] = event
  yield event
end

#stateObject



10
11
12
# File 'lib/r_machine/state_template.rb', line 10

def state
  @state_value
end

#state=(v) ⇒ Object



18
19
20
# File 'lib/r_machine/state_template.rb', line 18

def state=(v)
  @state_value = v
end