Class: GraphQL::DefinitionHelpers::StringNamedHash
- Inherits:
-
Object
- Object
- GraphQL::DefinitionHelpers::StringNamedHash
- 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
-
#to_h ⇒ Hash
readonly
Normalized hash for the input.
Instance Method Summary collapse
-
#initialize(input_hash) ⇒ StringNamedHash
constructor
A new instance of StringNamedHash.
Constructor Details
#initialize(input_hash) ⇒ StringNamedHash
Returns a new instance of StringNamedHash.
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_h ⇒ Hash (readonly)
Normalized hash for the input
9 10 11 |
# File 'lib/graphql/definition_helpers/string_named_hash.rb', line 9 def to_h @to_h end |