Skip to content

Enable passing options between blueprints via associations.#220

Merged
mcclayton merged 3 commits intomasterfrom
association-options
Jun 25, 2020
Merged

Enable passing options between blueprints via associations.#220
mcclayton merged 3 commits intomasterfrom
association-options

Conversation

@mcclayton
Copy link
Copy Markdown
Contributor

Enable passing options from one Blueprint to another via an association.

For example:

class VehicleBlueprint < Blueprinter::Base
  identifier :uuid
  field :full_name do |vehicle, options|
    "#{vehicle.model} #{options[:trim]}"
  end
end
class DriverBlueprint < Blueprinter::Base
  identifier :uuid
  view :normal do
    fields :first_name, :last_name
    association :vehicles, blueprint: vehicle_blueprint, options: { trim: 'LX' }
  end
end

@mcclayton mcclayton requested a review from philipqnguyen June 23, 2020 01:31
Comment thread lib/blueprinter/field.rb Outdated
def extract(object, local_options)
# If this is an association field, merge the association field options in
# to the render options
local_options = local_options.merge(options[:options]) if association? && options[:options]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we put this in the AssociationExtractor, since this is related to associations?

Comment thread lib/blueprinter/version.rb Outdated
@@ -1,3 +1,3 @@
module Blueprinter
VERSION = '0.23.4'.freeze
VERSION = '0.23.5'.freeze
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be 0.24.0?

As this is a new feature.

@mcclayton mcclayton merged commit 6a2b29b into master Jun 25, 2020
@mcclayton mcclayton deleted the association-options branch June 25, 2020 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants