Sha256: 11ed436d0835411a98149bc74aeb8272c9dcbc88a060b235430c17ee02425183

Contents?: true

Size: 893 Bytes

Versions: 1

Compression:

Stored size: 893 Bytes

Contents

module GraphQL
  class Query
    # Read-only access to values, normalizing all keys to strings
    #
    # {Arguments} recursively wraps the input in {Arguments} instances.
    class Arguments
      extend Forwardable

      def initialize(values)
        @values = values.inject({}) do |memo, (inner_key, inner_value)|
          memo[inner_key] = wrap_value(inner_value)
          memo
        end
      end

      # @param [String, Symbol] name or index of value to access
      # @return [Object] the argument at that key
      def [](key)
        @values[key.to_s]
      end

      def_delegators :@values_hash, :keys, :values, :each

      private

      def wrap_value(value)
        if value.is_a?(Array)
          value.map { |item| wrap_value(item) }
        elsif value.is_a?(Hash)
          self.class.new(value)
        else
          value
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
graphql-0.10.0 lib/graphql/query/arguments.rb