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.
-
#ddl ⇒ Object
Returns the value of attribute ddl.
-
#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.
- #fetch(key, default) ⇒ Object
-
#include?(key) ⇒ Boolean
If data is a hash, quick helper to get access to it’s include? method else returns false.
-
#initialize(msg, ddl) ⇒ 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
-
#validate! ⇒ Object
Validate the request against the DDL.
Constructor Details
#initialize(msg, ddl) ⇒ Request
Returns a new instance of Request.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/mcollective/rpc/request.rb', line 7 def initialize(msg, ddl) @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" @ddl = ddl 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 |
#ddl ⇒ Object
Returns the value of attribute ddl.
5 6 7 |
# File 'lib/mcollective/rpc/request.rb', line 5 def ddl @ddl 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
34 35 36 37 |
# File 'lib/mcollective/rpc/request.rb', line 34 def [](key) return nil unless @data.is_a?(Hash) return @data[key] end |
#fetch(key, default) ⇒ Object
39 40 41 42 |
# File 'lib/mcollective/rpc/request.rb', line 39 def fetch(key, default) return nil unless @data.is_a?(Hash) return @data.fetch(key, default) end |
#include?(key) ⇒ Boolean
If data is a hash, quick helper to get access to it’s include? method else returns false
20 21 22 23 |
# File 'lib/mcollective/rpc/request.rb', line 20 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
27 28 29 30 31 |
# File 'lib/mcollective/rpc/request.rb', line 27 def should_respond? return @data[:process_results] if @data.include?(:process_results) return true end |
#to_hash ⇒ Object
44 45 46 47 48 |
# File 'lib/mcollective/rpc/request.rb', line 44 def to_hash return {:agent => @agent, :action => @action, :data => @data} end |
#to_json ⇒ Object
55 56 57 58 59 |
# File 'lib/mcollective/rpc/request.rb', line 55 def to_json to_hash.merge!({:sender => @sender, :callerid => @callerid, :uniqid => @uniqid}).to_json end |
#validate! ⇒ Object
Validate the request against the DDL
51 52 53 |
# File 'lib/mcollective/rpc/request.rb', line 51 def validate! @ddl.validate_rpc_request(@action, @data) end |