Skip to content

Commit dc2d07c

Browse files
Merge branch 'main' into keyword-field-options
2 parents fb7fb0c + d40765c commit dc2d07c

File tree

6 files changed

+99
-13
lines changed

6 files changed

+99
-13
lines changed

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
1616
- name: Check if version has been updated
1717
id: check
18-
uses: tj-actions/changed-files@480f49412651059a414a6a5c96887abb1877de8a # v44
18+
uses: tj-actions/changed-files@db8d0bfea5a44e51abd5dc1454386c668ae901f9 # v44
1919
with:
2020
files: lib/blueprinter/version.rb
2121
release:

CHANGELOG.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
## Unreleased
2-
- [BREAKING] Drops support for Ruby 3.0. See [#496](https://github.com/procore-oss/blueprinter/pull/496)
2+
--
3+
4+
## 1.2.1 - 2025/09/11
5+
- 🐛 [BUGFIX] Adds back `Blueprinter.prepare` method with a deprecated warning. This method was previously public, but was removed as part of **1.2.0**.
6+
7+
## [REMOVED] 1.2.0 - 2025/09/10
8+
- ‼️ [BREAKING] Drops support for Ruby 3.0. See [#496](https://github.com/procore-oss/blueprinter/pull/496)
9+
- 💅 [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).
10+
- 🐛 [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).
11+
- 🚜 [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).
312

413
## 1.1.2 - 2024/10/3
514
- 🐛 [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
@@ -10,7 +19,7 @@
1019
* 🐛 [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).
1120

1221
## 1.1.0 - 2024/08/02
13-
* [BREAKING] Drops support for Ruby 2.7. See [#402](https://github.com/procore-oss/blueprinter/pull/402). Thanks to [@jmeridth](https://github.com/jmeridth)
22+
* ‼️ [BREAKING] Drops support for Ruby 2.7. See [#402](https://github.com/procore-oss/blueprinter/pull/402). Thanks to [@jmeridth](https://github.com/jmeridth)
1423
* 🚜 [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).
1524
* 💅 [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).
1625
* 💅 [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).
@@ -24,7 +33,7 @@
2433
* 🐛 [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).
2534

2635
## 1.0.0 - 2024/01/17
27-
* 🚀 [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).
36+
* ‼️ [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).
2837
* 🚀 [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).
2938
* 💅 [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).
3039

@@ -34,7 +43,7 @@
3443
* 💅 [ENHANCEMENT] Introduce rubocop
3544
* 💅 [ENHANCEMENT] if/:unless procs with two arguments and invalid empty type deprecations are now removed
3645
## 0.26.0 - 2023/08/17
37-
* 🐛 [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)
46+
* ‼️ [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)
3847

3948
## 0.25.3 - 2021/03/03
4049
* 🐛 [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).
@@ -175,7 +184,7 @@ a JSON String. See PR [#76](https://github.com/procore-oss/blueprinter/pull/76)
175184

176185
## 0.3.0 - 2018/04/05
177186

178-
💥 [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:
187+
‼️ [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:
179188

180189
```
181190
field(:first_name, serializer: CustomSerializer)
@@ -192,7 +201,7 @@ field(:first_name, extractor: CustomExtractor)
192201

193202
## 0.2.0 - 2018/01/22
194203

195-
💥 [BREAKING] Breaking Changes. To upgrade, ensure that any associated objects have a blueprint. For example:
204+
‼️ [BREAKING] Breaking Changes. To upgrade, ensure that any associated objects have a blueprint. For example:
196205
```
197206
association :comments, blueprint: CommentsBlueprint
198207
```

README.md

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ assoc[:category].options
10511051
<details>
10521052
<summary>Extensions</summary>
10531053

1054-
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.
10551055

10561056
```ruby
10571057
Blueprinter.configure do |config|
@@ -1060,13 +1060,53 @@ Blueprinter.configure do |config|
10601060
end
10611061
```
10621062

1063-
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
1105+
1106+
> **_NOTE:_** The following are not officially maintained/supported by Procore OSS.
10641107
1065-
* [pre_render](https://github.com/procore-oss/blueprinter/blob/abca9ca8ed23edd65a0f4b5ae43e25b8e27a2afc/lib/blueprinter/extension.rb#L18): Intercept the object before rendering begins
10661108

1067-
Some known extensions are:
10681109

1069-
* [blueprinter-activerecord](https://github.com/procore-oss/blueprinter-activerecord)
10701110
</details>
10711111

10721112
<details>

lib/blueprinter/rendering.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,26 @@ def hashify(object, view_name:, local_options:)
9696
prepare_data(object, view_name, local_options)
9797
end
9898

99+
# @deprecated This method is no longer supported, and was not originally intended to be public. This will be removed
100+
# in the next minor release. If similar functionality is needed, use `.render_as_hash` instead.
101+
#
102+
# This is the magic method that converts complex objects into a simple hash
103+
# ready for JSON conversion.
104+
#
105+
# Note: we accept view (public interface) that is in reality a view_name,
106+
# so we rename it for clarity
107+
#
108+
# @api private
109+
def prepare(object, view_name:, local_options:)
110+
Blueprinter::Deprecation.report(
111+
<<~MESSAGE
112+
The `prepare` method is no longer supported will be removed in the next minor release.
113+
If similar functionality is needed, use `.render_as_hash` instead.
114+
MESSAGE
115+
)
116+
render_as_hash(object, view_name:, local_options:)
117+
end
118+
99119
private
100120

101121
attr_reader :blueprint, :options

lib/blueprinter/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Blueprinter
4-
VERSION = '1.1.2'
4+
VERSION = '1.2.1'
55
end

spec/integrations/base_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,23 @@ def self.has_cars?(_field_name, object, local_options)
580580
end
581581
end
582582

583+
describe '.prepare' do
584+
subject { blueprint_with_block.prepare(object_with_attributes, view_name: :default, local_options: {}) }
585+
it 'returns a hash with expected format' do
586+
expect(subject).to eq({ id: object_with_attributes.id, position_and_company: "#{object_with_attributes.position} at #{object_with_attributes.company}"})
587+
end
588+
589+
it 'logs a deprecation warning' do
590+
expect(Blueprinter::Deprecation).to receive(:report).with(
591+
<<~MESSAGE
592+
The `prepare` method is no longer supported will be removed in the next minor release.
593+
If similar functionality is needed, use `.render_as_hash` instead.
594+
MESSAGE
595+
)
596+
subject
597+
end
598+
end
599+
583600
describe '::render_as_json' do
584601
subject { blueprint_with_block.render_as_json(object_with_attributes) }
585602
context 'Outside Rails project' do

0 commit comments

Comments
 (0)