class GraphQL::Execution::Lazy::LazyMethodMap

{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. @api private @see {Schema#lazy?} looks up values from this map

Attributes

storage[R]

Public Class Methods

new(use_concurrent: defined?(Concurrent::Map)) click to toggle source
# File lib/graphql/execution/lazy/lazy_method_map.rb, line 19
def initialize(use_concurrent: defined?(Concurrent::Map))
  @storage = use_concurrent ? Concurrent::Map.new : ConcurrentishMap.new
end

Public Instance Methods

each() { |k, v| ... } click to toggle source
# File lib/graphql/execution/lazy/lazy_method_map.rb, line 39
def each
  @storage.each_pair { |k, v| yield(k, v) }
end
get(value) click to toggle source

@param value [Object] an object which may have a ‘lazy_value_method` registered for its class or superclasses @return [Symbol, nil] The `lazy_value_method` for this object, or nil

# File lib/graphql/execution/lazy/lazy_method_map.rb, line 35
def get(value)
  @storage.compute_if_absent(value.class) { find_superclass_method(value.class) }
end
initialize_copy(other) click to toggle source
# File lib/graphql/execution/lazy/lazy_method_map.rb, line 23
def initialize_copy(other)
  @storage = other.storage.dup
end
set(lazy_class, lazy_value_method) click to toggle source

@param lazy_class [Class] A class which represents a lazy value (subclasses may also be used) @param lazy_value_method [Symbol] The method to call on this class to get its value

# File lib/graphql/execution/lazy/lazy_method_map.rb, line 29
def set(lazy_class, lazy_value_method)
  @storage[lazy_class] = lazy_value_method
end

Private Instance Methods

find_superclass_method(value_class) click to toggle source
# File lib/graphql/execution/lazy/lazy_method_map.rb, line 49
def find_superclass_method(value_class)
  @storage.each_pair { |lazy_class, lazy_value_method|
    return lazy_value_method if value_class < lazy_class
  }
  nil
end