Module: GraphQL::Autoload

Included in:
GraphQL, Query, Schema, Types
Defined in:
lib/graphql/autoload.rb

Instance Method Summary collapse

Instance Method Details

#autoload(const_name, path) ⇒ void

This method returns an undefined value.

Register a constant named const_name to be loaded from path. This is like Kernel#autoload but it tracks the constants so they can be eager-loaded with #eager_load!

Parameters:

  • const_name (Symbol)
  • path (String)


10
11
12
13
14
15
# File 'lib/graphql/autoload.rb', line 10

def autoload(const_name, path)
  @_eagerloaded_constants ||= []
  @_eagerloaded_constants << const_name

  super const_name, path
end

#eager_load!void

This method returns an undefined value.

Call this to load this constant’s autoload dependents and continue calling recursively



19
20
21
22
23
24
25
26
27
28
# File 'lib/graphql/autoload.rb', line 19

def eager_load!
  @_eager_loading = true
  if @_eagerloaded_constants
    @_eagerloaded_constants.each { |const_name| const_get(const_name) }
    @_eagerloaded_constants = nil
  end
  nil
ensure
  @_eager_loading = false
end