Class: Blueprinter::AssociationExtractor Private

Inherits:
Extractor
  • Object
show all
Includes:
EmptyTypes
Defined in:
lib/blueprinter/extractors/association_extractor.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

API:

  • private

Instance Method Summary collapse

Methods inherited from Extractor

extract

Constructor Details

#initializeAssociationExtractor

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of AssociationExtractor.

API:

  • private



11
12
13
# File 'lib/blueprinter/extractors/association_extractor.rb', line 11

def initialize
  @extractor = Blueprinter.configuration.default_extractor
end

Instance Method Details

#extract(association_name, object, local_options, options = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/blueprinter/extractors/association_extractor.rb', line 15

def extract(association_name, object, local_options, options = {})
  options_without_default = if options.key?(:default) || options.key?(:default_if)
                              options.except(:default, :default_if)
                            else
                              options
                            end

  value = @extractor.extract(association_name, object, local_options, options_without_default)
  return default_value(options) if use_default_value?(value, options[:default_if])

  # Merge in association options - supports both static Hash and dynamic Proc
  local_options = merge_association_options(local_options, options[:options], object)

  view = options[:view] || :default
  blueprint = association_blueprint(options[:blueprint], value)
  blueprint.hashify(value, view_name: view, local_options:)
end