Module: FSM::ClassMethods

Defined in:
lib/fsm.rb

Instance Method Summary collapse

Instance Method Details

#define_fsm(&block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/fsm.rb', line 7

def define_fsm(&block)
  raise 'FSM is already defined. Call define_fsm only once' if Machine[self]
  builder = Builder.new(self)
  Machine[self] = builder.process(&block)
  
  # TODO: check if all states are reachable
  # TODO: other checks? islands?
  
  # create alias for state attribute method to intercept it 
  # intercept
  FSM::StateAttributeInterceptor.add_interceptor(self)
end

#draw_graph(options = {}) ⇒ Object



20
21
22
23
24
# File 'lib/fsm.rb', line 20

def draw_graph(options = {})
  machine = Machine[self]
  raise 'No FSM defined. Call define_fsm first' unless machine
  machine.draw_graph(options)
end