Sha256: a0c1b0620bd9401ec2504bab5c6612e22d0e4e91431b1f66e269a66975de6e70

Contents?: true

Size: 1.07 KB

Versions: 29

Compression:

Stored size: 1.07 KB

Contents

module MCollective
  module Data
    class Result
      # remove some methods that might clash with commonly
      # used return data to improve the effectiveness of the
      # method_missing lookup strategy
      undef :type if method_defined?(:type)

      def initialize(outputs)
        @data = {}

        outputs.keys.each do |output|
          @data[output] = Marshal.load(Marshal.dump(outputs[output].fetch(:default, nil)))
        end
      end

      def include?(key)
        @data.include?(key.to_sym)
      end

      def [](key)
        @data[key.to_sym]
      end

      def []=(key, val)
        raise "Can only store String, Integer, Float or Boolean data but got #{val.class} for key #{key}" unless [String, Fixnum, Bignum, Float, TrueClass, FalseClass].include?(val.class)

        @data[key.to_sym] = val
      end

      def keys
        @data.keys
      end

      def method_missing(method, *args)
        key = method.to_sym

        raise NoMethodError, "undefined local variable or method `%s'" % key unless include?(key)

        @data[key]
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

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