Class: MCollective::RPC::Result
- Inherits:
-
Object
- Object
- MCollective::RPC::Result
- Includes:
- Enumerable
- Defined in:
- lib/mcollective/rpc/result.rb
Overview
Simple class to manage compliant results from MCollective::RPC agents
Currently it just fakes Hash behaviour to the result to remain backward compatible but it also knows which agent and action produced it so you can associate results to a DDL
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #[](idx) ⇒ Object
- #[]=(idx, item) ⇒ Object
- #each ⇒ Object
- #fetch(key, default) ⇒ Object
-
#initialize(agent, action, result = {}) ⇒ Result
constructor
A new instance of Result.
- #to_json(*a) ⇒ Object
Constructor Details
#initialize(agent, action, result = {}) ⇒ Result
Returns a new instance of Result.
13 14 15 16 17 |
# File 'lib/mcollective/rpc/result.rb', line 13 def initialize(agent, action, result={}) @agent = agent @action = action @results = result end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
9 10 11 |
# File 'lib/mcollective/rpc/result.rb', line 9 def action @action end |
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
9 10 11 |
# File 'lib/mcollective/rpc/result.rb', line 9 def agent @agent end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
9 10 11 |
# File 'lib/mcollective/rpc/result.rb', line 9 def results @results end |
Instance Method Details
#<=>(other) ⇒ Object
44 45 46 |
# File 'lib/mcollective/rpc/result.rb', line 44 def <=>(other) self[:sender] <=> other[:sender] end |
#[](idx) ⇒ Object
19 20 21 |
# File 'lib/mcollective/rpc/result.rb', line 19 def [](idx) @results[idx] end |
#[]=(idx, item) ⇒ Object
23 24 25 |
# File 'lib/mcollective/rpc/result.rb', line 23 def []=(idx, item) @results[idx] = item end |
#each ⇒ Object
31 32 33 |
# File 'lib/mcollective/rpc/result.rb', line 31 def each @results.each_pair {|k,v| yield(k,v) } end |
#fetch(key, default) ⇒ Object
27 28 29 |
# File 'lib/mcollective/rpc/result.rb', line 27 def fetch(key, default) @results.fetch(key, default) end |
#to_json(*a) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/mcollective/rpc/result.rb', line 35 def to_json(*a) {:agent => @agent, :action => @action, :sender => @results[:sender], :statuscode => @results[:statuscode], :statusmsg => @results[:statusmsg], :data => @results[:data]}.to_json(*a) end |