Class: AutoPreload::Resolver

Inherits:
Object
  • Object
show all
Defined in:
lib/auto_preload/resolver.rb

Overview

This class parses a string in the format “articles,comments” and returns an array of symbols.

Constant Summary collapse

MAX_ITERATIONS =

Default max number of iterations

Returns:

  • (Integer)
100

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Resolver

Returns a new instance of Resolver.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):



13
14
15
16
17
18
# File 'lib/auto_preload/resolver.rb', line 13

def initialize(options = {})
  @iterations = 0
  @options = options
  @max_iterations = options[:max_iterations] || MAX_ITERATIONS
  @adapter = AutoPreload.config.adapter
end

Instance Method Details

#resolve(query, inclusions) ⇒ Array<Symbol, Hash>

Resolves a string as an array of symbols or hashes.

Parameters:

  • query (ActiveRecord::Base, ActiveRecord::Relation)
  • inclusions (String, Array<String>)

Returns:

  • (Array<Symbol, Hash>)


25
26
27
28
29
# File 'lib/auto_preload/resolver.rb', line 25

def resolve(query, inclusions)
  model = query.respond_to?(:klass) ? query.klass : query

  format_output(run_resolve(model, inclusions, root: true))
end