Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft release for v0.19.0 #169

Merged
merged 2 commits into from
Jul 24, 2019
Merged

Draft release for v0.19.0 #169

merged 2 commits into from
Jul 24, 2019

Conversation

mcclayton
Copy link
Contributor

@mcclayton mcclayton commented Jul 24, 2019

0.19.0 - 2019/07/24

  • 🚀 [FEATURE] Added ability to specify transformers for Blueprinter views to further process the resulting hash before serialization. #164. Thanks to @amalarayfreshworks.

Readme Section

Transform Classes

Blueprinter provides the ability to specify transforms on views, which enable further
processing and transforming of resulting view field hashes prior to serialization.

Use transform to specify one transformer to be included for serialization.
A transformer is a class, extending Blueprinter::Transformer and implementing the transform method.
Whatever is returned from this transform method will end up being the resulting hash passed to serialization.

Example

Create a Transform class extending from Blueprinter::Transformer

class DynamicFieldTransformer < Blueprinter::Transformer
  def transform(hash, object, options)
    hash.merge!(object.dynamic_fields)
  end
end
class User
  def custom_columns
    self.dynamic_fields #which is an array of some columns
  end
  def custom_fields
    custom_columns.each_with_object({}){|col,result|  result[col] = self.send(col)}
  end
end

Then specify the transform to use for the view.

class UserBlueprint < Blueprinter::Base
  fields :first_name, :last_name
  transform DynamicTransformer
end

@mcclayton mcclayton merged commit 140aaa3 into master Jul 24, 2019
@mcclayton mcclayton deleted the v0.19.0 branch July 24, 2019 23:17
@mcclayton mcclayton restored the v0.19.0 branch July 24, 2019 23:17
@jmeridth jmeridth deleted the v0.19.0 branch July 26, 2023 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants