Class: Blueprinter::AssociationExtractor

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

Instance Method Summary collapse

Methods inherited from Extractor

extract

Constructor Details

#initializeAssociationExtractor

Returns a new instance of AssociationExtractor.



3
4
5
# File 'lib/blueprinter/extractors/association_extractor.rb', line 3

def initialize
  @extractor = AutoExtractor.new
end

Instance Method Details

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



7
8
9
10
11
12
13
14
# File 'lib/blueprinter/extractors/association_extractor.rb', line 7

def extract(association_name, object, local_options, options={})
  options_without_default = options.reject { |k,_| k == :default }
  value = @extractor.extract(association_name, object, local_options, options_without_default)
  return default_value(options) if value.nil?
  view = options[:view] || :default
  blueprint = association_blueprint(options[:blueprint], value)
  blueprint.prepare(value, view_name: view, local_options: local_options)
end