Method: BlueprinterActiveRecord::Preloader#initialize

Defined in:
lib/blueprinter-activerecord/preloader.rb

#initialize(auto: false, use: :preload) {|Object, Class, Symbol, Hash| ... } ⇒ Preloader

Initialize and configure the extension.

Parameters:

  • auto (true|false) (defaults to: false)

    When true, preload for EVERY ActiveRecord::Relation passed to a Blueprint

  • use (:preload|:includes) (defaults to: :preload)

    When auto is true, use this method (e.g. :preload) for preloading

Yields:

  • (Object, Class, Symbol, Hash)

    Instead of passing auto as a boolean, you may define a block that accepts the object to render, the blueprint class, the view, and options. If the block returns true, auto preloading will take place.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/blueprinter-activerecord/preloader.rb', line 18

def initialize(auto: false, use: :preload, &auto_proc)
  @auto = auto
  @auto_proc = auto_proc
  @use =
    case use
    when :preload, :includes
      use
    else
      raise ArgumentError, "Unknown value '#{use.inspect}' for `BlueprinterActiveRecord::Preloader` argument 'use'. Valid values are :preload, :includes."
    end
end