Class MCollective::RPC::Request
In: lib/mcollective/rpc/request.rb
Parent: Object

Simple class to manage compliant requests for MCollective::RPC agents

Methods

[]   include?   new   should_respond?   to_hash   to_json  

Attributes

action  [RW] 
agent  [RW] 
caller  [RW] 
data  [RW] 
sender  [RW] 
time  [RW] 
uniqid  [RW] 

Public Class methods

[Source]

    # File lib/mcollective/rpc/request.rb, line 7
 7:       def initialize(msg)
 8:         @time = msg[:msgtime]
 9:         @action = msg[:body][:action]
10:         @data = msg[:body][:data]
11:         @sender = msg[:senderid]
12:         @agent = msg[:body][:agent]
13:         @uniqid = msg[:requestid]
14:         @caller = msg[:callerid] || "unknown"
15:       end

Public Instance methods

If data is a hash, gives easy access to its members, else returns nil

[Source]

    # File lib/mcollective/rpc/request.rb, line 33
33:       def [](key)
34:         return nil unless @data.is_a?(Hash)
35:         return @data[key]
36:       end

If data is a hash, quick helper to get access to it‘s include? method else returns false

[Source]

    # File lib/mcollective/rpc/request.rb, line 19
19:       def include?(key)
20:         return false unless @data.is_a?(Hash)
21:         return @data.include?(key)
22:       end

If no :process_results is specified always respond else respond based on the supplied property

[Source]

    # File lib/mcollective/rpc/request.rb, line 26
26:       def should_respond?
27:         return @data[:process_results] if @data.include?(:process_results)
28: 
29:         return true
30:       end

[Source]

    # File lib/mcollective/rpc/request.rb, line 38
38:       def to_hash
39:         return {:agent => @agent,
40:           :action => @action,
41:           :data => @data}
42:       end

[Source]

    # File lib/mcollective/rpc/request.rb, line 44
44:       def to_json
45:         to_hash.merge!({:sender   => @sender,
46:                          :callerid => @callerid,
47:                          :uniqid   => @uniqid}).to_json
48:       end

[Validate]