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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 580e993c5873c53b1324841946e603d64cc53549fa171467683b0d4777bb3375
4
- data.tar.gz: 297c9ff83b8b2a726970e099034631e9f9200ff4598f896c465885a982a86e04
3
+ metadata.gz: bf9b763f4f3719ba9e005676312f09f21165d8bc53ede0ee5ac0d171fcbae828
4
+ data.tar.gz: 2984aa6879ecafa6e15e49a95edc0b3fdad19d0f3ef0cdb51c484a7785b05303
5
5
  SHA512:
6
- metadata.gz: b7ba1f23e5cd9f50a7c1c97269d6830ed832d4018ba29c24ee208e8105be53f0034ce52c7f851f12d2c4a876f8093202fa7c99306bd50c74f1663edca0a82cbe
7
- data.tar.gz: a66d70cf431cdd6ada7633cf1ee067a8701a5eaef4ba2d9d9cea0344a81565603357ba0dafa548cac4db870bc131b7aca263ead7c389b4b0d15264ec4dff2315
6
+ metadata.gz: 8141264e23abc76304a7dc22527880e22c82b1dbb796e4b4f9f5cbd6bd3a0b95c029aa83f3d68b557c530904b0131b19338fde99b00693374b95f529d6424027
7
+ data.tar.gz: 74c36b42fdb6655084572d94c7cb8ac610855c587604c3aae4c093590fb0254641de043a1b58d25ed2c963db42209d85444fdcdd8370189d766228136804b37d
@@ -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
 
@@ -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
- # def custom_columns
290
- # self.dynamic_fields #which is an array of some columns
291
- # end
292
- # def custom_fields
293
- # custom_columns.each_with_object({}){|col,result| result[col] = self.send(col)}
294
- # end
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 DynamicTransformer
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.
@@ -1,5 +1,4 @@
1
1
  module Blueprinter
2
- # @api private
3
2
  class Extractor
4
3
  def extract(field_name, object, local_options, options={})
5
4
  fail NotImplementedError, "An Extractor must implement #extract"
@@ -1,4 +1,5 @@
1
1
  module Blueprinter
2
+ # @api private
2
3
  class AssociationExtractor < Extractor
3
4
  def initialize
4
5
  @extractor = AutoExtractor.new
@@ -1,4 +1,5 @@
1
1
  module Blueprinter
2
+ # @api private
2
3
  class AutoExtractor < Extractor
3
4
  def initialize
4
5
  @hash_extractor = HashExtractor.new
@@ -1,4 +1,5 @@
1
1
  module Blueprinter
2
+ # @api private
2
3
  class BlockExtractor < Extractor
3
4
  def extract(field_name, object, local_options, options = {})
4
5
  options[:block].call(object, local_options)
@@ -1,4 +1,5 @@
1
1
  module Blueprinter
2
+ # @api private
2
3
  class HashExtractor < Extractor
3
4
  def extract(field_name, object, _local_options, _options = {})
4
5
  object[field_name]
@@ -1,4 +1,5 @@
1
1
  module Blueprinter
2
+ # @api private
2
3
  class PublicSendExtractor < Extractor
3
4
  def extract(field_name, object, local_options, options = {})
4
5
  object.public_send(field_name)
@@ -1,3 +1,3 @@
1
1
  module Blueprinter
2
- VERSION = '0.19.0'
2
+ VERSION = '0.20.0'
3
3
  end
@@ -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.19.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-07-25 00:00:00.000000000 Z
12
+ date: 2019-10-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: factory_bot