Class: GraphQL::StringNamedHash
- Inherits:
-
Object
- Object
- GraphQL::StringNamedHash
- Defined in:
- lib/graph_ql/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`
Instance Attribute Summary collapse
-
#to_h ⇒ Object
readonly
Returns the value of attribute to_h.
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.
6 7 8 9 10 11 |
# File 'lib/graph_ql/definition_helpers/string_named_hash.rb', line 6 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 ⇒ Object (readonly)
Returns the value of attribute to_h.
5 6 7 |
# File 'lib/graph_ql/definition_helpers/string_named_hash.rb', line 5 def to_h @to_h end |