Skip to content

Commit

Permalink
Merge pull request #169 from procore/v0.19.0
Browse files Browse the repository at this point in the history
Draft release for v0.19.0
  • Loading branch information
mcclayton authored Jul 24, 2019
2 parents 6cb2784 + 80144f3 commit 140aaa3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.19.0 - 2019/07/24
* 🚀 [FEATURE] Added ability to specify transformers for Blueprinter views to further process the resulting hash before serialization. [#164](https://github.com/procore/blueprinter/pull/164). Thanks to [@amalarayfreshworks](https://github.com/amalarayfreshworks).

## 0.18.0 - 2019/05/29

* ⚠️ [DEPRECATION] :if/:unless procs with two arguments are now deprecated. *These procs now take in three arguments (field_name, obj, options) instead of just (obj, options).*
Expand Down
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,53 @@ _NOTE:_ The field-level setting overrides the global config setting (for the fie
</details>


<details>
<summary>Transform Classes</summary>

---

Blueprinter provides the ability to specify `transform`s 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`
```ruby
class DynamicFieldTransformer < Blueprinter::Transformer
def transform(hash, object, options)
hash.merge!(object.dynamic_fields)
end
end
```

```ruby
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.
```ruby
class UserBlueprint < Blueprinter::Base
fields :first_name, :last_name
transform DynamicTransformer
end
```

---
</details>


<details>
<summary>Sorting Fields</summary>

Expand Down
2 changes: 1 addition & 1 deletion lib/blueprinter/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Blueprinter
VERSION = '0.18.0'
VERSION = '0.19.0'
end

0 comments on commit 140aaa3

Please sign in to comment.