Class: GraphQL::Execution::Lazy::LazyMethodMap
- Inherits:
-
Object
- Object
- GraphQL::Execution::Lazy::LazyMethodMap
- Defined in:
- lib/graphql/execution/lazy/lazy_method_map.rb
Overview
GraphQL::Schema uses this to match returned values to lazy resolution methods.
Methods may be registered for classes, they apply to its subclasses also.
The result of this lookup is cached for future resolutions.
Instances of this class are thread-safe.
See the schema's lazy? configuration to understand which values use this map.
Defined Under Namespace
Classes: ConcurrentishMap
Instance Method Summary collapse
- #each ⇒ Object
-
#get(value) ⇒ Object
Parameters.
-
#initialize(use_concurrent: defined?(Concurrent::Map)) ⇒ LazyMethodMap
constructor
:nodoc:.
- #initialize_copy(other) ⇒ Object
-
#set(lazy_class, lazy_value_method) ⇒ Object
Parameters.
Constructor Details
#initialize(use_concurrent: defined?(Concurrent::Map)) ⇒ LazyMethodMap
:nodoc:
20 21 22 |
# File 'lib/graphql/execution/lazy/lazy_method_map.rb', line 20 def initialize(use_concurrent: defined?(Concurrent::Map)) @storage = use_concurrent ? Concurrent::Map.new : ConcurrentishMap.new end |
Instance Method Details
#each ⇒ Object
53 54 55 |
# File 'lib/graphql/execution/lazy/lazy_method_map.rb', line 53 def each @storage.each_pair { |k, v| yield(k, v) } end |
#get(value) ⇒ Object
Parameters
value(Object) — an object which may have alazy_value_methodregistered for its class or superclasses
Returns
Symbol, nil— Thelazy_value_methodfor this object, or nil
:call-seq:
get(Object value) -> Symbol | nil
49 50 51 |
# File 'lib/graphql/execution/lazy/lazy_method_map.rb', line 49 def get(value) @storage.compute_if_absent(value.class) { find_superclass_method(value.class) } end |
#initialize_copy(other) ⇒ Object
24 25 26 |
# File 'lib/graphql/execution/lazy/lazy_method_map.rb', line 24 def initialize_copy(other) @storage = other.storage.dup end |
#set(lazy_class, lazy_value_method) ⇒ Object
Parameters
lazy_class(Class) — A class which represents a lazy value (subclasses may also be used)lazy_value_method(Symbol) — The method to call on this class to get its value
:call-seq:
set(Class lazy_class, Symbol lazy_value_method)
35 36 37 |
# File 'lib/graphql/execution/lazy/lazy_method_map.rb', line 35 def set(lazy_class, lazy_value_method) @storage[lazy_class] = lazy_value_method end |