Class: BlueprinterActiveRecord::PreloadInfo
- Inherits:
-
Object
- Object
- BlueprinterActiveRecord::PreloadInfo
- 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
-
#query ⇒ ActiveRecord::Relation
readonly
The base query.
-
#trace ⇒ Array<String>
readonly
Stack trace to the query.
Instance Method Summary collapse
-
#found ⇒ Array<Array<Symbol>>
Array of “preload paths” (e.g. [[:project, :company]]) to missing preloads that could have been found & added by BlueprinterActiveRecord::Preloader.
-
#hash ⇒ Hash
Nested hash of all preloads, both manually added and auto found.
-
#initialize(query, from_code, from_blueprint, trace) ⇒ PreloadInfo
constructor
A new instance of PreloadInfo.
-
#num_existing ⇒ Integer
The number of preloads, includes, and eager_loads that existed before BlueprinterActiveRecord was involved.
-
#percent_found ⇒ Integer
The percent of total preloads found by BlueprinterActiveRecord.
-
#visible ⇒ Array<Array<Symbol>>
Array of “preload paths” (e.g. [[:project, :company]]) from the blueprint that were visible to the preloader.
Methods included from Helpers
#count_preloads, #diff_preloads, #extract_preloads, #merge_values
Constructor Details
#initialize(query, from_code, from_blueprint, trace) ⇒ PreloadInfo
Returns a new instance of 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
#query ⇒ ActiveRecord::Relation (readonly)
Returns The base query.
13 14 15 |
# File 'lib/blueprinter-activerecord/preload_info.rb', line 13 def query @query end |
#trace ⇒ Array<String> (readonly)
Returns Stack trace to the query.
16 17 18 |
# File 'lib/blueprinter-activerecord/preload_info.rb', line 16 def trace @trace end |
Instance Method Details
#found ⇒ Array<Array<Symbol>>
Returns Array of “preload paths” (e.g. [[:project, :company]]) to missing preloads that could have been found & added by BlueprinterActiveRecord::Preloader.
43 44 45 |
# File 'lib/blueprinter-activerecord/preload_info.rb', line 43 def found @found ||= diff_preloads(@from_code, hash) end |
#hash ⇒ Hash
Returns Nested hash of all preloads, both manually added and auto found.
53 54 55 |
# File 'lib/blueprinter-activerecord/preload_info.rb', line 53 def hash @hash ||= merge_values [@from_code, @from_blueprint] end |
#num_existing ⇒ Integer
Returns The number of preloads, includes, and eager_loads that existed before BlueprinterActiveRecord was involved.
38 39 40 |
# File 'lib/blueprinter-activerecord/preload_info.rb', line 38 def num_existing @num_existing ||= count_preloads(hash) end |
#percent_found ⇒ Integer
Returns The percent of total preloads found by BlueprinterActiveRecord.
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 |
#visible ⇒ Array<Array<Symbol>>
Returns Array of “preload paths” (e.g. [[:project, :company]]) from the blueprint that were visible to the preloader.
48 49 50 |
# File 'lib/blueprinter-activerecord/preload_info.rb', line 48 def visible @visible ||= diff_preloads({}, @from_blueprint) end |