Class: Emissary::Agent

Inherits:
Object show all
Defined in:
lib/emissary/agent.rb

Direct Known Subclasses

Emissary, Error, File, Gem, Mysql, Ping, Proxy, Rabbitmq, Stats, Test

Defined Under Namespace

Classes: Emissary, Error, File, Gem, Mysql, Ping, Proxy, Rabbitmq, Stats, Test

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, config, operator) ⇒ Agent

Returns a new instance of Agent.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/emissary/agent.rb', line 21

def initialize message, config, operator
  @message  = message
  @operator = operator
  @config   = config
  
  @method   = message.method.to_sym rescue :__bad_method__
  @args     = message.args.clone
  
  unless valid_methods.first == :any or valid_methods.include? @method 
    raise ArgumentError, "Invalid method '#{@method.to_s}' for agent '#{message.agent}'"
  end
  
  post_init
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



19
20
21
# File 'lib/emissary/agent.rb', line 19

def args
  @args
end

#configObject (readonly)

Returns the value of attribute config.



18
19
20
# File 'lib/emissary/agent.rb', line 18

def config
  @config
end

#messageObject (readonly)

Returns the value of attribute message.



18
19
20
# File 'lib/emissary/agent.rb', line 18

def message
  @message
end

#methodObject (readonly)

Returns the value of attribute method.



18
19
20
# File 'lib/emissary/agent.rb', line 18

def method
  @method
end

#nameObject (readonly)

Returns the value of attribute name.



18
19
20
# File 'lib/emissary/agent.rb', line 18

def name
  @name
end

#operatorObject (readonly)

Returns the value of attribute operator.



18
19
20
# File 'lib/emissary/agent.rb', line 18

def operator
  @operator
end

Instance Method Details

#activateObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/emissary/agent.rb', line 42

def activate
  catch(:skip_implicit_response) do
    result = self.__send__(method, *args)
    response = if not result.kind_of? ::Emissary::Message
      response = message.response
      response.status = [ :ok, (result == true || result.nil? ? 'Succeeded.' : result ) ]
      response
    else
      result
    end
    
    send response
  end
end

#post_initObject



36
# File 'lib/emissary/agent.rb', line 36

def post_init(); end

#send(message) ⇒ Object



57
58
59
# File 'lib/emissary/agent.rb', line 57

def send message
  operator.send message
end

#valid_methodsObject

Raises:

  • (StandardError)


38
39
40
# File 'lib/emissary/agent.rb', line 38

def valid_methods
  raise StandardError, 'Not implemented'
end