Class: Aquam::Machine
Instance Attribute Summary collapse
Instance Method Summary
collapse
event, events, state, states, transition
Constructor Details
#initialize(object) ⇒ Machine
Returns a new instance of Machine.
9
10
11
|
# File 'lib/aquam/machine.rb', line 9
def initialize(object)
@object = object
end
|
Instance Attribute Details
#object ⇒ Object
Returns the value of attribute object.
7
8
9
|
# File 'lib/aquam/machine.rb', line 7
def object
@object
end
|
Instance Method Details
#current_state ⇒ Object
25
26
27
28
29
|
# File 'lib/aquam/machine.rb', line 25
def current_state
fail Aquam::InvalidStateError unless valid_state?
self.class.states[attribute].new object
end
|
#trigger(event, *args) ⇒ Object
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/aquam/machine.rb', line 31
def trigger(event, *args)
state = current_state
fail Aquam::InvalidEventError unless valid_event? event
fail Aquam::InvalidTransitionError unless valid_transition? event
state.send event, *args
current_state
end
|
#valid_event?(event) ⇒ Boolean
17
18
19
|
# File 'lib/aquam/machine.rb', line 17
def valid_event?(event)
self.class.valid_event? event
end
|
#valid_state? ⇒ Boolean
13
14
15
|
# File 'lib/aquam/machine.rb', line 13
def valid_state?
self.class.valid_state? attribute
end
|
#valid_transition?(event) ⇒ Boolean
21
22
23
|
# File 'lib/aquam/machine.rb', line 21
def valid_transition?(event)
self.class.events[event].key? attribute
end
|