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.

See Also:

  • looks up values from this map

Instance Method Summary collapse

Constructor Details

#initialize ⇒ 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.



11
12
13
14
15
16
17
18
19
20
# File 'lib/graphql/execution/lazy/lazy_method_map.rb', line 11

def initialize
  @storage = Hash.new do |h, value_class|
    registered_superclass = h.each_key.find { |lazy_class| value_class < lazy_class }
    if registered_superclass.nil?
      h[value_class] = nil
    else
      h[value_class] = h[registered_superclass]
    end
  end
end

Instance Method Details

#each ⇒ 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.



34
35
36
# File 'lib/graphql/execution/lazy/lazy_method_map.rb', line 34

def each
  @storage.each { |k, v| yield(k,v) }
end

#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



30
31
32
# File 'lib/graphql/execution/lazy/lazy_method_map.rb', line 30

def get(value)
  @storage[value.class]
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



24
25
26
# File 'lib/graphql/execution/lazy/lazy_method_map.rb', line 24

def set(lazy_class, lazy_value_method)
  @storage[lazy_class] = lazy_value_method
end