Sha256: 6d85595f9919354ea45b58d9e5a126fc1c308d9e4dd4b1844bd19c87bc3e0679

Contents?: true

Size: 1.12 KB

Versions: 21

Compression:

Stored size: 1.12 KB

Contents

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

      def <=>(other)
        self[:sender] <=> other[:sender]
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
mcollective-client-2.10.6 lib/mcollective/rpc/result.rb
mcollective-client-2.10.4 lib/mcollective/rpc/result.rb
mcollective-client-2.10.3 lib/mcollective/rpc/result.rb
mcollective-client-2.10.2 lib/mcollective/rpc/result.rb
mcollective-client-2.10.1 lib/mcollective/rpc/result.rb
mcollective-client-2.10.0 lib/mcollective/rpc/result.rb
mcollective-client-2.8.7 lib/mcollective/rpc/result.rb
mcollective-client-2.8.5 lib/mcollective/rpc/result.rb
mcollective-client-2.8.8 lib/mcollective/rpc/result.rb
mcollective-client-2.8.6 lib/mcollective/rpc/result.rb
mcollective-client-2.9.1 lib/mcollective/rpc/result.rb
mcollective-client-2.9.0 lib/mcollective/rpc/result.rb
mcollective-client-2.8.9 lib/mcollective/rpc/result.rb
mcollective-client-2.8.4 lib/mcollective/rpc/result.rb
mcollective-client-2.8.3 lib/mcollective/rpc/result.rb
mcollective-client-2.8.2 lib/mcollective/rpc/result.rb
mcollective-client-2.8.1 lib/mcollective/rpc/result.rb
mcollective-client-2.8.0 lib/mcollective/rpc/result.rb
mcollective-client-2.7.0 lib/mcollective/rpc/result.rb
mcollective-client-2.6.1 lib/mcollective/rpc/result.rb