Method: Blueprinter::Base.association
- Defined in:
- lib/blueprinter/base.rb
.association(method, options = {}) {|object, options| ... } ⇒ Association
Specify an associated object to be included for serialization. Takes a required method and an option.
155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/blueprinter/base.rb', line 155 def association(method, = {}, &block) raise ArgumentError, ':blueprint must be provided when defining an association' unless [:blueprint] method = method.to_sym current_view << Association.new( method:, name: .fetch(:name) { method }, extractor: .fetch(:extractor) { AssociationExtractor.new }, blueprint: .fetch(:blueprint), parent_blueprint: self, view: .fetch(:view, :default), options: .except(:name, :extractor, :blueprint, :view).merge(block:) ) end |