Class: Lab42::StateMachine

Inherits:
Object
  • Object
show all
Extended by:
Forwarder
Defined in:
lib/lab42/state_machine.rb,
lib/lab42/state_machine/version.rb,
lib/lab42/state_machine/controller.rb,
lib/lab42/state_machine/controller/stream_api.rb

Defined Under Namespace

Classes: Controller

Constant Summary collapse

Version =
"0.2.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#subjectObject

Returns the value of attribute subject.



7
8
9
# File 'lib/lab42/state_machine.rb', line 7

def subject
  @subject
end

Instance Method Details

#behavior(name, &behave) ⇒ Object



11
12
13
14
15
# File 'lib/lab42/state_machine.rb', line 11

def behavior name, &behave
  class << self; self end. module_eval do
    define_method name do behave end
  end
end

#clone(new_subject = nil, &redefinition) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/lab42/state_machine.rb', line 17

def clone new_subject=nil, &redefinition
  old_controller = controller
  copy = self.class.new( new_subject || subject.clone ){
    controller.send :inherit_from!, old_controller
  }
  copy.instance_eval( &redefinition ) if redefinition
  copy
end

#halt_machineObject

Raises:

  • (StopIteration)


26
27
28
# File 'lib/lab42/state_machine.rb', line 26

def halt_machine
  raise StopIteration, "#{self} halted"
end

#run(input = []) ⇒ Object



30
31
32
33
# File 'lib/lab42/state_machine.rb', line 30

def run input=[]
  controller.run input
  subject
end