Module: Pione::Agent::StateTransitionSingletonMethod

Included in:
BasicAgent
Defined in:
lib/pione/agent/basic-agent.rb

Overview

StateTransitionSingleMethod provides state transition singleton methods.

Instance Method Summary collapse

Instance Method Details

#chain(data) ⇒ Object

Define a transition chain.



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/pione/agent/basic-agent.rb', line 38

def chain(data)
  data.each do |k, v|
    raise ArgumentError.new(k) if not(@transitions.include?(k))
    if not(v.is_a?(Proc))
      (v.is_a?(Array) ? v : [v]).each do |_v|
        raise ArgumentError.new(_v) if not(@transitions.include?(_v))
      end
    end
  end
  transition_chain.merge!(data)
end

#define_exception_handler(data) ⇒ Object

Define a transition for handling exceptions.



56
57
58
# File 'lib/pione/agent/basic-agent.rb', line 56

def define_exception_handler(data)
  exception_handler.merge!(data)
end

#define_transition(name) ⇒ Object

Defines a new transition.



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pione/agent/basic-agent.rb', line 20

def define_transition(name)
  @transitions ||= []
  unless @transitions.include?(name)
    @transitions << name

    # define empty transition method
    unless method_defined?("transit_to_#{name}")
      define_method("transit_to_#{name}") {}
    end
  end
end

#exception_handlerObject

Return exception handler table.



51
52
53
# File 'lib/pione/agent/basic-agent.rb', line 51

def exception_handler
  @exception_handler ||= {}
end

#start(*args, &b) ⇒ Object

Creates an agent and starts it.



61
62
63
64
# File 'lib/pione/agent/basic-agent.rb', line 61

def start(*args, &b)
  agent = new(*args, &b)
  return agent.start
end

#transition_chainObject

Returns transition chain table.



33
34
35
# File 'lib/pione/agent/basic-agent.rb', line 33

def transition_chain
  @transition_chain ||= {nil => :init}
end