Class: GraphQL::Execution::Lazy::LazyMethodMap Private

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/execution/lazy/lazy_method_map.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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 Also:

  • looks up values from this map

Defined Under Namespace

Classes: ConcurrentishMap

Instance Method Summary collapse

Constructor Details

#initialize(use_concurrent: defined?(Concurrent::Map)) ⇒ LazyMethodMap

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of LazyMethodMap.



19
20
21
# 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

Instance Method Details

#get(value) ⇒ Symbol?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The lazy_value_method for this object, or nil.

Parameters:

  • value (Object)

    an object which may have a lazy_value_method registered for its class or superclasses

Returns:

  • (Symbol, nil)

    The lazy_value_method for this object, or nil



35
36
37
# 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) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



23
24
25
# 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) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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



29
30
31
# 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