Class: GraphQL::Query::LookupHash
- Inherits:
-
Object
- Object
- GraphQL::Query::LookupHash
- Defined in:
- lib/graphql/query.rb
Overview
Caches items by name, raises an error if not found
Instance Attribute Summary collapse
-
#item_name ⇒ Object
readonly
Returns the value of attribute item_name.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Instance Method Summary collapse
- #[](identifier) ⇒ Object
-
#initialize(item_name, items) ⇒ LookupHash
constructor
A new instance of LookupHash.
Constructor Details
#initialize(item_name, items) ⇒ LookupHash
Returns a new instance of LookupHash.
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/graphql/query.rb', line 93 def initialize(item_name, items) @items = items @item_name = item_name @storage = Hash.new do |hash, identifier| value = items.find {|i| i.identifier == identifier } if value.blank? "No #{item_name} found for #{identifier}, defined #{item_name}s are: #{items.map(&:identifier)}" end hash[identifier] = value end end |
Instance Attribute Details
#item_name ⇒ Object (readonly)
Returns the value of attribute item_name.
92 93 94 |
# File 'lib/graphql/query.rb', line 92 def item_name @item_name end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
92 93 94 |
# File 'lib/graphql/query.rb', line 92 def items @items end |
Instance Method Details
#[](identifier) ⇒ Object
105 106 107 |
# File 'lib/graphql/query.rb', line 105 def [](identifier) @storage[identifier] end |