Sha256: 4249dc8be86a9c0629f3c455633f9d30c30c40ce651e566b53a6460eb550a0a9

Contents?: true

Size: 1.21 KB

Versions: 22

Compression:

Stored size: 1.21 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)
        # checks using the string representation of the class name to avoid deprecations on Bignum and Fixnum
        raise "Can only store String, Integer, Float or Boolean data but got #{val.class} for key #{key}" unless ["String", "Integer", "Bignum", "Fixnum", "Float", "TrueClass", "FalseClass"].include?(val.class.to_s)

        @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

22 entries across 22 versions & 2 rubygems

Version Path
choria-mcorpc-support-2.22.1 lib/mcollective/data/result.rb
choria-mcorpc-support-2.22.0 lib/mcollective/data/result.rb
choria-mcorpc-support-2.21.1 lib/mcollective/data/result.rb
choria-mcorpc-support-2.21.0 lib/mcollective/data/result.rb
choria-mcorpc-support-2.20.8 lib/mcollective/data/result.rb
mcollective-client-2.12.5 lib/mcollective/data/result.rb
choria-mcorpc-support-2.20.7 lib/mcollective/data/result.rb
choria-mcorpc-support-2.20.6 lib/mcollective/data/result.rb
choria-mcorpc-support-2.20.5 lib/mcollective/data/result.rb
choria-mcorpc-support-2.20.4 lib/mcollective/data/result.rb
choria-mcorpc-support-2.20.3 lib/mcollective/data/result.rb
choria-mcorpc-support-2.20.2 lib/mcollective/data/result.rb
choria-mcorpc-support-2.20.0 lib/mcollective/data/result.rb
choria-mcorpc-support-0.0.1 lib/mcollective/data/result.rb
mcollective-client-2.12.4 lib/mcollective/data/result.rb
mcollective-client-2.12.3 lib/mcollective/data/result.rb
mcollective-client-2.12.1 lib/mcollective/data/result.rb
mcollective-client-2.12.0 lib/mcollective/data/result.rb
mcollective-client-2.11.4 lib/mcollective/data/result.rb
mcollective-client-2.11.3 lib/mcollective/data/result.rb