blueprinter 0.19.0 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +3 -2
- data/lib/blueprinter/base.rb +36 -7
- data/lib/blueprinter/extractor.rb +0 -1
- data/lib/blueprinter/extractors/association_extractor.rb +1 -0
- data/lib/blueprinter/extractors/auto_extractor.rb +1 -0
- data/lib/blueprinter/extractors/block_extractor.rb +1 -0
- data/lib/blueprinter/extractors/hash_extractor.rb +1 -0
- data/lib/blueprinter/extractors/public_send_extractor.rb +1 -0
- data/lib/blueprinter/version.rb +1 -1
- data/lib/blueprinter/view.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf9b763f4f3719ba9e005676312f09f21165d8bc53ede0ee5ac0d171fcbae828
|
4
|
+
data.tar.gz: 2984aa6879ecafa6e15e49a95edc0b3fdad19d0f3ef0cdb51c484a7785b05303
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8141264e23abc76304a7dc22527880e22c82b1dbb796e4b4f9f5cbd6bd3a0b95c029aa83f3d68b557c530904b0131b19338fde99b00693374b95f529d6424027
|
7
|
+
data.tar.gz: 74c36b42fdb6655084572d94c7cb8ac610855c587604c3aae4c093590fb0254641de043a1b58d25ed2c963db42209d85444fdcdd8370189d766228136804b37d
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## 0.20.0 - 2019/10/15
|
2
|
+
* 🚀 [FEATURE] Ability to include multiple views in a single method call with `include_views`. [184](https://github.com/procore/blueprinter/pull/184). Thanks to [@narendranvelmurugan](https://github.com/narendranvelmurugan).
|
3
|
+
|
4
|
+
* 💅 [ENHANCEMENT] Update field-level conditional settings to reflect new three-argument syntax. [183](https://github.com/procore/blueprinter/pull/183). Thanks to [@danirod](https://github.com/danirod).
|
5
|
+
|
6
|
+
* 💅 [ENHANCEMENT] Modify Extractor access control in documentation. [182](https://github.com/procore/blueprinter/pull/182). Thanks to [@cagmz](https://github.com/cagmz).
|
7
|
+
|
8
|
+
* 💅 [ENHANCEMENT] Fix the Transformer example documentation. [174](https://github.com/procore/blueprinter/pull/174). Thanks to [@tjwallace](https://github.com/tjwallace).
|
9
|
+
|
1
10
|
## 0.19.0 - 2019/07/24
|
2
11
|
* 🚀 [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).
|
3
12
|
|
data/README.md
CHANGED
@@ -137,6 +137,7 @@ class UserBlueprint < Blueprinter::Base
|
|
137
137
|
end
|
138
138
|
end
|
139
139
|
```
|
140
|
+
A view can include fields from another view by utilizing `include_view` and `include_views`.
|
140
141
|
|
141
142
|
Usage:
|
142
143
|
```ruby
|
@@ -590,8 +591,8 @@ end
|
|
590
591
|
```ruby
|
591
592
|
class UserBlueprint < Blueprinter::Base
|
592
593
|
identifier :uuid
|
593
|
-
field :last_name, if: ->(user, options) { user.first_name != options[:first_name] }
|
594
|
-
field :age, unless: ->(user, _options) { user.age < 18 }
|
594
|
+
field :last_name, if: ->(_field_name, user, options) { user.first_name != options[:first_name] }
|
595
|
+
field :age, unless: ->(_field_name, user, _options) { user.age < 18 }
|
595
596
|
end
|
596
597
|
```
|
597
598
|
|
data/lib/blueprinter/base.rb
CHANGED
@@ -286,17 +286,18 @@ module Blueprinter
|
|
286
286
|
#
|
287
287
|
# @example Specifying a DynamicFieldTransformer transformer for including dynamic fields to be serialized.
|
288
288
|
# class User
|
289
|
-
#
|
290
|
-
#
|
291
|
-
#
|
292
|
-
#
|
293
|
-
#
|
294
|
-
#
|
289
|
+
# def custom_columns
|
290
|
+
# self.dynamic_fields # which is an array of some columns
|
291
|
+
# end
|
292
|
+
#
|
293
|
+
# def custom_fields
|
294
|
+
# custom_columns.each_with_object({}) { |col,result| result[col] = self.send(col) }
|
295
|
+
# end
|
295
296
|
# end
|
296
297
|
#
|
297
298
|
# class UserBlueprint < Blueprinter::Base
|
298
299
|
# fields :first_name, :last_name
|
299
|
-
# transform
|
300
|
+
# transform DynamicFieldTransformer
|
300
301
|
# # other code
|
301
302
|
# end
|
302
303
|
#
|
@@ -335,6 +336,34 @@ module Blueprinter
|
|
335
336
|
end
|
336
337
|
|
337
338
|
|
339
|
+
# Specify additional views that should be mixed into the current view.
|
340
|
+
#
|
341
|
+
# @param view_name [Array<Symbol>] the views to mix into the current view.
|
342
|
+
#
|
343
|
+
# @example Including the normal and special views into an extended view.
|
344
|
+
# class UserBlueprint < Blueprinter::Base
|
345
|
+
# # other code...
|
346
|
+
# view :normal do
|
347
|
+
# fields :first_name, :last_name
|
348
|
+
# end
|
349
|
+
# view :special do
|
350
|
+
# fields :birthday, :company
|
351
|
+
# end
|
352
|
+
# view :extended do
|
353
|
+
# include_views :normal, :special # include fields specified from above.
|
354
|
+
# field :description
|
355
|
+
# end
|
356
|
+
# #=> [:first_name, :last_name, :birthday, :company, :description]
|
357
|
+
# end
|
358
|
+
#
|
359
|
+
# @return [Array<Symbol>] an array of view names.
|
360
|
+
|
361
|
+
|
362
|
+
def self.include_views(*view_names)
|
363
|
+
current_view.include_views(view_names)
|
364
|
+
end
|
365
|
+
|
366
|
+
|
338
367
|
# Exclude a field that was mixed into the current view.
|
339
368
|
#
|
340
369
|
# @param field_name [Symbol] the field to exclude from the current view.
|
data/lib/blueprinter/version.rb
CHANGED
data/lib/blueprinter/view.rb
CHANGED
@@ -33,6 +33,12 @@ module Blueprinter
|
|
33
33
|
included_view_names << view_name
|
34
34
|
end
|
35
35
|
|
36
|
+
def include_views(view_names)
|
37
|
+
view_names.each do |view_name|
|
38
|
+
included_view_names << view_name
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
36
42
|
def exclude_field(field_name)
|
37
43
|
excluded_field_names << field_name
|
38
44
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blueprinter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.20.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Hess
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-10-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: factory_bot
|