blueprinter 1.1.2 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca694fd9e2b31d1b48e7fafb2637a67b2e83835d90d51126dfa5c2520147b4b1
4
- data.tar.gz: eb7dbb1f64149a475a4b768883fac8d9b8d20e6dad061a1f2ceadd5f1aa10a35
3
+ metadata.gz: 72b769b814788e3b67f5cf11fc9e15322f20240cf436eb81004d7014b1a89755
4
+ data.tar.gz: a975d061a805def418f281ef7012f3aa6031448c15e092578cab127a8c06e3bc
5
5
  SHA512:
6
- metadata.gz: a8fee9e8d383bd1f7fcf92124373cd06070327e16264f5d8dd281c18a8393f7bea9eea6a93252e30d46f899063c4e2bf2a79e0b7d7af2e890a847b8a03af766a
7
- data.tar.gz: 8971833f761e56d13e41a93c688ecca7d7c1213e432db0f61ba8786c9f68851b1978f0bbb6618e5c935bd8e07c6268d3e8bcc5f5e57f6e188e78a83322253bc0
6
+ metadata.gz: 2ff9c8a8af880ac84e7352b7e989dc84b05573d494a105879d65661a0f2db6441b69ff799531e4ccd2cc4f14e31cfb9e6acd416f43d2f70f8a6f9edde4dc4fe8
7
+ data.tar.gz: f46db4bfc8eaa1c3d60132e4c69872bc20c116c59033e36916e5dbaeebdc2ecac0c68d3c4abab80d7f45e6adb835602f0540d6c3a4e0582296a1d5ec075c0883
data/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ ## Unreleased
2
+ --
3
+
4
+ ## 1.3.0 - 2026/04/14
5
+ - 🚀 [FEATURE] Adds support for `Symbol#to_proc` syntax in fields and identifiers. See [#546](https://github.com/procore-oss/blueprinter/pull/546). Thanks to [@tob1k](https://github.com/tob1k).
6
+ - 🚀 [FEATURE] Adds support for Proc in association `:options` parameter, enabling dynamic options based on the parent object. See [#579](https://github.com/procore-oss/blueprinter/pull/579). Thanks to [@lessthanjacob](https://github.com/lessthanjacob).
7
+ - 🐛 [BUGFIX] Passes options as keywords during block extraction. See [#521](https://github.com/procore-oss/blueprinter/pull/521). Thanks to [@tylerhunt](https://github.com/tylerhunt).
8
+ - 🐛 [BUGFIX] Ensures `Deprecation` module gets loaded before it's used. See [#549](https://github.com/procore-oss/blueprinter/pull/549). Thanks to [@jhollinger](https://github.com/jhollinger).
9
+ - 🐛 [BUGFIX] Fixes `ViewCollection` cache invalidation after view block evaluation, preventing silent loss of mutations when `reflections` triggers early cache compilation. See [#579](https://github.com/procore-oss/blueprinter/pull/579). Thanks to [@lessthanjacob](https://github.com/lessthanjacob).
10
+ - 🚜 [REFACTOR] Caches `ViewCollection` and transformers to reduce object allocations and improve rendering performance. See [#566](https://github.com/procore-oss/blueprinter/pull/566). Thanks to [@lessthanjacob](https://github.com/lessthanjacob).
11
+
12
+ ## 1.2.1 - 2025/09/11
13
+ - 🐛 [BUGFIX] Adds back `Blueprinter.prepare` method with a deprecated warning. This method was previously public, but was removed as part of **1.2.0**.
14
+
15
+ ## [REMOVED] 1.2.0 - 2025/09/10
16
+ - ‼️ [BREAKING] Drops support for Ruby 3.0. See [#496](https://github.com/procore-oss/blueprinter/pull/496)
17
+ - 💅 [ENHANCEMENT] Allows for the current view to be accessible from within the `options` hash provided to the `field` block. See [#503](https://github.com/procore-oss/blueprinter/pull/503). Thanks to [@neo87cs](https://github.com/neo87cs).
18
+ - 🐛 [BUGFIX] Fixes an issue where specifying fields using a mix of symbols and strings would cause an `ArgumentError` when rendering. See [#505](https://github.com/procore-oss/blueprinter/pull/505). Thanks to [@lessthanjacob](https://github.com/lessthanjacob).
19
+ - 🚜 [REFACTOR] Reorganizes rendering/serialization logic and removes `BaseHelper` module. See [#476](https://github.com/procore-oss/blueprinter/pull/476). Thanks to [@lessthanjacob](https://github.com/lessthanjacob).
20
+
1
21
  ## 1.1.2 - 2024/10/3
2
22
  - 🐛 [BUGFIX] Fixes an issue where a `Blueprinter::BlueprinterError` would be raised on render when providing `view: nil`, instead of falling back on the `:default` view. See
3
23
  [#472](https://github.com/procore-oss/blueprinter/pull/472). Thanks to [@lessthanjacob](https://github.com/lessthanjacob).
@@ -7,7 +27,7 @@
7
27
  * 🐛 [BUGFIX] Fixes an issue when passing in a `Symbol` (representing a method) to the `if:` condition on an association. The provided `Symbol` would be erroneously sent to the association's Blueprint, instead of the Blueprint in which the association was defined within. See [#464](https://github.com/procore-oss/blueprinter/pull/464). Thanks to [@lessthanjacob](https://github.com/lessthanjacob).
8
28
 
9
29
  ## 1.1.0 - 2024/08/02
10
- * [BREAKING] Drops support for Ruby 2.7. See [#402](https://github.com/procore-oss/blueprinter/pull/402). Thanks to [@jmeridth](https://github.com/jmeridth)
30
+ * ‼️ [BREAKING] Drops support for Ruby 2.7. See [#402](https://github.com/procore-oss/blueprinter/pull/402). Thanks to [@jmeridth](https://github.com/jmeridth)
11
31
  * 🚜 [REFACTOR] Cleans up Blueprint validation logic and implements an `Association` class with a clearer interface. See [#414](https://github.com/procore-oss/blueprinter/pull/414). Thanks to [@lessthanjacob](https://github.com/lessthanjacob).
12
32
  * 💅 [ENHANCEMENT] Updates **Transform Classes** documentation to provide a more understandable example. See [#415](https://github.com/procore-oss/blueprinter/pull/415). Thanks to [@SaxtonDrey](https://github.com/SaxtonDrey).
13
33
  * 💅 [ENHANCEMENT] Implements field-level configuration option for excluding an attribute from the result of a render if its value is `nil`. See [#425](https://github.com/procore-oss/blueprinter/pull/425). Thanks to [jamesst20](https://github.com/jamesst20).
@@ -21,7 +41,7 @@
21
41
  * 🐛 [BUGFIX] Fixes an issue where serialization performance would become degraded when using a Blueprint that leverages transformers. See [#381](https://github.com/procore-oss/blueprinter/pull/381). Thanks to [@Pritilender](https://github.com/Pritilender).
22
42
 
23
43
  ## 1.0.0 - 2024/01/17
24
- * 🚀 [BREAKING] Allow transformers to be included across views. See [README](https://github.com/procore-oss/blueprinter#transform-across-views), PR [#372](https://github.com/procore-oss/blueprinter/pull/372) and issue [#225](https://github.com/procore-oss/blueprinter/issues/225) for details. Note this changes the behavior of transformers which were previously only applied to the view they were defined on. Thanks to [@njbbaer](https://github.com/njbbaer) and [@bhooshiek-narendiran](https://github.com/bhooshiek-narendiran).
44
+ * ‼️ [BREAKING] Allow transformers to be included across views. See [README](https://github.com/procore-oss/blueprinter#transform-across-views), PR [#372](https://github.com/procore-oss/blueprinter/pull/372) and issue [#225](https://github.com/procore-oss/blueprinter/issues/225) for details. Note this changes the behavior of transformers which were previously only applied to the view they were defined on. Thanks to [@njbbaer](https://github.com/njbbaer) and [@bhooshiek-narendiran](https://github.com/bhooshiek-narendiran).
25
45
  * 🚀 [FEATURE] Introduce extension API, with initial support for pre_render hook. See [#358](https://github.com/procore-oss/blueprinter/pull/358) for details. Thanks to [@jhollinger](https://github.com/jhollinger).
26
46
  * 💅 [ENHANCEMENT] Add reflection on views, fields, and associations. See PR [#357](https://github.com/procore-oss/blueprinter/pull/357), and issue [#341](https://github.com/procore-oss/blueprinter/issues/341) for details. Thanks to [@jhollinger](https://github.com/jhollinger).
27
47
 
@@ -31,7 +51,7 @@
31
51
  * 💅 [ENHANCEMENT] Introduce rubocop
32
52
  * 💅 [ENHANCEMENT] if/:unless procs with two arguments and invalid empty type deprecations are now removed
33
53
  ## 0.26.0 - 2023/08/17
34
- * 🐛 [BREAKING] Transition to GitHub Actions from CircleCI and update to handle Ruby versions 2.7, 3.0, 3.1, 3.2. Drop support for any ruby version less than 2.7. See [#307](https://github.com/procore-oss/blueprinter/pull/307)
54
+ * ‼️ [BREAKING] Transition to GitHub Actions from CircleCI and update to handle Ruby versions 2.7, 3.0, 3.1, 3.2. Drop support for any ruby version less than 2.7. See [#307](https://github.com/procore-oss/blueprinter/pull/307)
35
55
 
36
56
  ## 0.25.3 - 2021/03/03
37
57
  * 🐛 [BUGFIX] Fixes issue where fields and associations that are redefined by later views were not properly overwritten. See [#201](https://github.com/procore-oss/blueprinter/pull/201) thanks to [@Berardpi](https://github.com/Berardpi).
@@ -172,7 +192,7 @@ a JSON String. See PR [#76](https://github.com/procore-oss/blueprinter/pull/76)
172
192
 
173
193
  ## 0.3.0 - 2018/04/05
174
194
 
175
- 💥 [BREAKING] Sort of a breaking Change. Serializer classes has been renamed to Extractor. To upgrade, if you passed in a specific serializer to `field` or `identifier` such as:
195
+ ‼️ [BREAKING] Sort of a breaking Change. Serializer classes has been renamed to Extractor. To upgrade, if you passed in a specific serializer to `field` or `identifier` such as:
176
196
 
177
197
  ```
178
198
  field(:first_name, serializer: CustomSerializer)
@@ -189,7 +209,7 @@ field(:first_name, extractor: CustomExtractor)
189
209
 
190
210
  ## 0.2.0 - 2018/01/22
191
211
 
192
- 💥 [BREAKING] Breaking Changes. To upgrade, ensure that any associated objects have a blueprint. For example:
212
+ ‼️ [BREAKING] Breaking Changes. To upgrade, ensure that any associated objects have a blueprint. For example:
193
213
  ```
194
214
  association :comments, blueprint: CommentsBlueprint
195
215
  ```
data/README.md CHANGED
@@ -561,6 +561,44 @@ Output:
561
561
 
562
562
  </details>
563
563
 
564
+ <details>
565
+ <summary>Accessing the View Option</summary>
566
+
567
+
568
+ The `view` provided to the `render` call is implicitly available in the `options` hash within a `field` block, and can be referenced as needed. For example:
569
+
570
+ ```ruby
571
+ class UserBlueprint < Blueprinter::Base
572
+ identifier :uuid
573
+ field :full_name do |user, options|
574
+ prefix = options[:view] == :admin ? '[Admin]' : options[:title_prefix]
575
+ "#{prefix} #{user.first_name} #{user.last_name}"
576
+ end
577
+
578
+ view :admin do
579
+ field :access_level
580
+ end
581
+ end
582
+ ```
583
+
584
+ Usage:
585
+
586
+ ```ruby
587
+ puts UserBlueprint.render(user, title_prefix: "Mr", view: :admin)
588
+ ```
589
+
590
+ Output:
591
+
592
+ ```json
593
+ {
594
+ "uuid": "733f0758-8f21-4719-875f-262c3ec743af",
595
+ "full_name": "[Admin] John Doe",
596
+ "access_level": "4"
597
+ }
598
+ ```
599
+
600
+ </details>
601
+
564
602
  <details>
565
603
  <summary>Defining An Identifier Directly In The Blueprint</summary>
566
604
 
@@ -1013,7 +1051,7 @@ assoc[:category].options
1013
1051
  <details>
1014
1052
  <summary>Extensions</summary>
1015
1053
 
1016
- Blueprinter offers an extension system to hook into and modify certain behavior.
1054
+ Blueprinter provides an extension system that enables certain behavior to be modified as needed.
1017
1055
 
1018
1056
  ```ruby
1019
1057
  Blueprinter.configure do |config|
@@ -1022,13 +1060,53 @@ Blueprinter.configure do |config|
1022
1060
  end
1023
1061
  ```
1024
1062
 
1025
- Extension hooks:
1063
+ #### Available Hooks
1064
+
1065
+ * **pre_render** - Intercept the object before rendering begins. This allows you to modify, transform, or replace the object that will be serialized.
1066
+
1067
+ #### Creating Extensions
1068
+
1069
+ To create an extension, simply subclass `Blueprinter::Extension` and override the method representing the desired hook:
1070
+
1071
+ ```ruby
1072
+ class ObfuscateNameExtension < Blueprinter::Extension
1073
+ def pre_render(object, blueprint, view, options)
1074
+ return object unless object.respond_to?(:name)
1075
+
1076
+ modified_object = object.dup
1077
+ modified_object.name = ObsfuscateName.call(modified_object.name)
1078
+
1079
+ modified_object
1080
+ end
1081
+ end
1082
+ ```
1083
+
1084
+ #### Extension Execution Order
1085
+
1086
+ Extensions are executed in the order they are added to the configuration. Each extension receives the result from the previous extension, allowing for chained transformations:
1087
+
1088
+ ```ruby
1089
+ Blueprinter.configure do |config|
1090
+ config.extensions << SecurityExtension.new # Runs first
1091
+ config.extensions << AssociationLoaderExtension.new # Runs second
1092
+ config.extensions << UserEnrichmentExtension.new # Runs third
1093
+ end
1094
+ ```
1095
+
1096
+ #### Gem Extensions
1097
+
1098
+ Gems can be created that enrich `blueprinter`'s core functionality via extensions.
1099
+
1100
+ ##### Procore Supported Gems
1101
+
1102
+ * [blueprinter-activerecord](https://github.com/procore-oss/blueprinter-activerecord) - Provides ActiveRecord-specific optimizations and features
1103
+
1104
+ ##### Community Gems
1026
1105
 
1027
- * [pre_render](https://github.com/procore-oss/blueprinter/blob/abca9ca8ed23edd65a0f4b5ae43e25b8e27a2afc/lib/blueprinter/extension.rb#L18): Intercept the object before rendering begins
1106
+ > **_NOTE:_** The following are not officially maintained/supported by Procore OSS.
1028
1107
 
1029
- Some known extensions are:
1108
+ * [blueprinter_schema](https://github.com/thisismydesign/blueprinter_schema) - Create JSON Schemas from Blueprinter Serializers
1030
1109
 
1031
- * [blueprinter-activerecord](https://github.com/procore-oss/blueprinter-activerecord)
1032
1110
  </details>
1033
1111
 
1034
1112
  <details>
@@ -25,8 +25,8 @@ module Blueprinter
25
25
  extractor,
26
26
  parent_blueprint,
27
27
  options.merge(
28
- blueprint: blueprint,
29
- view: view,
28
+ blueprint:,
29
+ view:,
30
30
  association: true
31
31
  )
32
32
  )