Class: MCollective::RPC::Request
- Inherits:
-
Object
- Object
- MCollective::RPC::Request
- Defined in:
- lib/mcollective/rpc/request.rb
Overview
Simple class to manage compliant requests for MCollective::RPC agents
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#agent ⇒ Object
Returns the value of attribute agent.
-
#caller ⇒ Object
Returns the value of attribute caller.
-
#data ⇒ Object
Returns the value of attribute data.
-
#sender ⇒ Object
Returns the value of attribute sender.
-
#time ⇒ Object
Returns the value of attribute time.
-
#uniqid ⇒ Object
Returns the value of attribute uniqid.
Instance Method Summary collapse
-
#[](key) ⇒ Object
If data is a hash, gives easy access to its members, else returns nil.
-
#include?(key) ⇒ Boolean
If data is a hash, quick helper to get access to it’s include? method else returns false.
-
#initialize(msg) ⇒ Request
constructor
A new instance of Request.
-
#should_respond? ⇒ Boolean
If no :process_results is specified always respond else respond based on the supplied property.
- #to_hash ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(msg) ⇒ Request
Returns a new instance of Request.
7 8 9 10 11 12 13 14 15 |
# File 'lib/mcollective/rpc/request.rb', line 7 def initialize(msg) @time = msg[:msgtime] @action = msg[:body][:action] @data = msg[:body][:data] @sender = msg[:senderid] @agent = msg[:body][:agent] @uniqid = msg[:requestid] @caller = msg[:callerid] || "unknown" end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
5 6 7 |
# File 'lib/mcollective/rpc/request.rb', line 5 def action @action end |
#agent ⇒ Object
Returns the value of attribute agent.
5 6 7 |
# File 'lib/mcollective/rpc/request.rb', line 5 def agent @agent end |
#caller ⇒ Object
Returns the value of attribute caller.
5 6 7 |
# File 'lib/mcollective/rpc/request.rb', line 5 def caller @caller end |
#data ⇒ Object
Returns the value of attribute data.
5 6 7 |
# File 'lib/mcollective/rpc/request.rb', line 5 def data @data end |
#sender ⇒ Object
Returns the value of attribute sender.
5 6 7 |
# File 'lib/mcollective/rpc/request.rb', line 5 def sender @sender end |
#time ⇒ Object
Returns the value of attribute time.
5 6 7 |
# File 'lib/mcollective/rpc/request.rb', line 5 def time @time end |
#uniqid ⇒ Object
Returns the value of attribute uniqid.
5 6 7 |
# File 'lib/mcollective/rpc/request.rb', line 5 def uniqid @uniqid end |
Instance Method Details
#[](key) ⇒ Object
If data is a hash, gives easy access to its members, else returns nil
33 34 35 36 |
# File 'lib/mcollective/rpc/request.rb', line 33 def [](key) return nil unless @data.is_a?(Hash) return @data[key] end |
#include?(key) ⇒ Boolean
If data is a hash, quick helper to get access to it’s include? method else returns false
19 20 21 22 |
# File 'lib/mcollective/rpc/request.rb', line 19 def include?(key) return false unless @data.is_a?(Hash) return @data.include?(key) end |
#should_respond? ⇒ Boolean
If no :process_results is specified always respond else respond based on the supplied property
26 27 28 29 30 |
# File 'lib/mcollective/rpc/request.rb', line 26 def should_respond? return @data[:process_results] if @data.include?(:process_results) return true end |
#to_hash ⇒ Object
38 39 40 41 42 |
# File 'lib/mcollective/rpc/request.rb', line 38 def to_hash return {:agent => @agent, :action => @action, :data => @data} end |
#to_json ⇒ Object
44 45 46 47 48 |
# File 'lib/mcollective/rpc/request.rb', line 44 def to_json to_hash.merge!({:sender => @sender, :callerid => @callerid, :uniqid => @uniqid}).to_json end |