X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=lib%2Fmcollective%2Frpc%2Fresult.rb;fp=lib%2Fmcollective%2Frpc%2Fresult.rb;h=291fd69cd64499e3df3aa218d0edbe441845a5ee;hb=b87d2f4e68281062df1913440ca5753ae63314a9;hp=0000000000000000000000000000000000000000;hpb=ab0ea530b8ac956091f17b104ab2311336cfc250;p=packages%2Fprecise%2Fmcollective.git diff --git a/lib/mcollective/rpc/result.rb b/lib/mcollective/rpc/result.rb new file mode 100644 index 0000000..291fd69 --- /dev/null +++ b/lib/mcollective/rpc/result.rb @@ -0,0 +1,45 @@ +module MCollective + module RPC + # 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 + class Result + attr_reader :agent, :action, :results + + include Enumerable + + def initialize(agent, action, result={}) + @agent = agent + @action = action + @results = result + end + + def [](idx) + @results[idx] + end + + def []=(idx, item) + @results[idx] = item + end + + def fetch(key, default) + @results.fetch(key, default) + end + + def each + @results.each_pair {|k,v| yield(k,v) } + end + + def to_json(*a) + {:agent => @agent, + :action => @action, + :sender => @results[:sender], + :statuscode => @results[:statuscode], + :statusmsg => @results[:statusmsg], + :data => @results[:data]}.to_json(*a) + end + end + end +end