class MCollective::RPC::Result - mcollective version 2.12.5

# class MCollective::RPC::Result

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`

### Attributes

action[R]
agent[R]
results[R]

### Public Class Methods

new(agent, action, result={}) click to toggle source

       # File lib/mcollective/rpc/result.rb
    13 def initialize(agent, action, result={})
    14   @agent = agent
    15   @action = action
    16   @results = result
    17
    18   convert_data_based_on_ddl if ddl
    19 end

### Public Instance Methods

<=>(other) click to toggle source

       # File lib/mcollective/rpc/result.rb
    85 def <=>(other)
    86   self[:sender] <=> other[:sender]
    87 end

[](key) click to toggle source

       # File lib/mcollective/rpc/result.rb
    60 def [](key)
    61   @results[compatible_key(key)]
    62 end

[]=(key, item) click to toggle source

       # File lib/mcollective/rpc/result.rb
    64 def []=(key, item)
    65   @results[key] = item
    66 end

compatible_key(key) click to toggle source

       # File lib/mcollective/rpc/result.rb
    52 def compatible_key(key)
    53   if key.is_a?(Symbol) && @results.include?(key.to_s)
    54     key.to_s
    55   else
    56     key
    57   end
    58 end

convert_data_based_on_ddl() click to toggle source

Converts keys on the supplied data to those listed as outputs in the `DDL`. This is to facilitate JSON based transports without forcing everyone to rewrite DDLs and clients to convert symbols to strings, the data will be on symbol keys if the `DDL` has a symbol and not a string output defined

       # File lib/mcollective/rpc/result.rb
    38 def convert_data_based_on_ddl
    39   interface = ddl.action_interface(action)
    40
    41   return if interface.fetch(:output, {}).empty?
    42
    43   interface[:output].each do |output, properties|
    44     next if data.include?(output)
    45
    46     if output.is_a?(Symbol) && data.include?(output.to_s)
    47       data[output] = data.delete(output.to_s)
    48     end
    49   end
    50 end

data() click to toggle source

       # File lib/mcollective/rpc/result.rb
    27 def data
    28   @results[:data] = @results.delete("data") if @results.include?("data")
    29
    30   self[:data]
    31 end

ddl() click to toggle source

       # File lib/mcollective/rpc/result.rb
    21 def ddl
    22   @_ddl ||= DDL.new(agent)
    23 rescue
    24   nil
    25 end

each() { |k,v| ... } click to toggle source

       # File lib/mcollective/rpc/result.rb
    72 def each
    73   @results.each_pair {|k,v| yield(k,v) }
    74 end

fetch(key, default) click to toggle source

       # File lib/mcollective/rpc/result.rb
    68 def fetch(key, default)
    69   @results.fetch(compatible_key(key), default)
    70 end

to_json(*a) click to toggle source

       # File lib/mcollective/rpc/result.rb
    76 def to_json(*a)
    77   {:agent => @agent,
    78    :action => @action,
    79    :sender => self[:sender],
    80    :statuscode => self[:statuscode],
    81    :statusmsg => self[:statusmsg],
    82    :data => data}.to_json(*a)
    83 end