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.6.1 lib/mcollective/data/result.rb
mcollective-client-2.6.0 lib/mcollective/data/result.rb
mcollective-client-2.5.3 lib/mcollective/data/result.rb
mcollective-client-2.5.2 lib/mcollective/data/result.rb
mcollective-client-2.5.1 lib/mcollective/data/result.rb
mcollective-client-2.5.0 lib/mcollective/data/result.rb
mcollective-client-2.5.0.rc1 lib/mcollective/data/result.rb
mcollective-client-2.4.1 lib/mcollective/data/result.rb
mcollective-client-2.4.0 lib/mcollective/data/result.rb