Class: GraphQL::DefinitionHelpers::StringNamedHash

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/definition_helpers/string_named_hash.rb

Overview

Accepts a hash with symbol keys.

  • convert keys to strings

  • if the value responds to ‘name=`, then assign the hash key as `name`

Used by ObjectType#fields, Field#arguments and others.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_hash) ⇒ StringNamedHash

Returns a new instance of StringNamedHash.

Parameters:

  • input_hash (Hash)

    Hash to be normalized



12
13
14
15
16
17
# File 'lib/graphql/definition_helpers/string_named_hash.rb', line 12

def initialize(input_hash)
  @to_h = input_hash
    .reduce({}) { |memo, (key, value)| memo[key.to_s] = value; memo }
  # Set the name of the value based on its key
  @to_h.each {|k, v| v.respond_to?("name=") && v.name = k }
end

Instance Attribute Details

#to_hHash (readonly)

Normalized hash for the input

Returns:

  • (Hash)

    Hash with string keys



9
10
11
# File 'lib/graphql/definition_helpers/string_named_hash.rb', line 9

def to_h
  @to_h
end