Class: BlueprinterActiveRecord::PreloadInfo

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/blueprinter-activerecord/preload_info.rb

Overview

Info about preloads from a query that was run through a Blueprinter’s render method.

Used for logging by the BlueprinterActiveRecord::MissingPreloadsLogger and BlueprinterActiveRecord::AddedPreloadsLogger extensions.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#count_preloads, #diff_preloads, #extract_preloads, #merge_values

Constructor Details

#initialize(query, from_code, from_blueprint, trace) ⇒ PreloadInfo



24
25
26
27
28
29
# File 'lib/blueprinter-activerecord/preload_info.rb', line 24

def initialize(query, from_code, from_blueprint, trace)
  @query = query
  @from_code = from_code
  @from_blueprint = from_blueprint
  @trace = trace
end

Instance Attribute Details

#queryActiveRecord::Relation (readonly)



13
14
15
# File 'lib/blueprinter-activerecord/preload_info.rb', line 13

def query
  @query
end

#traceArray<String> (readonly)



16
17
18
# File 'lib/blueprinter-activerecord/preload_info.rb', line 16

def trace
  @trace
end

Instance Method Details

#foundArray<Array<Symbol>>



43
44
45
# File 'lib/blueprinter-activerecord/preload_info.rb', line 43

def found
  @found ||= diff_preloads(@from_code, hash)
end

#hashHash



53
54
55
# File 'lib/blueprinter-activerecord/preload_info.rb', line 53

def hash
  @hash ||= merge_values [@from_code, @from_blueprint]
end

#num_existingInteger



38
39
40
# File 'lib/blueprinter-activerecord/preload_info.rb', line 38

def num_existing
  @num_existing ||= count_preloads(hash)
end

#percent_foundInteger



32
33
34
35
# File 'lib/blueprinter-activerecord/preload_info.rb', line 32

def percent_found
  total = num_existing + found.size
  ((found.size / num_existing.to_f) * 100).round
end

#visibleArray<Array<Symbol>>



48
49
50
# File 'lib/blueprinter-activerecord/preload_info.rb', line 48

def visible
  @visible ||= diff_preloads({}, @from_blueprint)
end