blueprinter 0.17.0 → 0.18.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: 2f9861d74164769103ef0e80689c8685cc1ba1fee08ef296b5dd3c383dec6403
4
- data.tar.gz: bb5a57d899eae1e5d3cf1bd4deef908ea7e34988d5bfd1284e75e8835a5208bb
3
+ metadata.gz: 58305ea0b747a19614cf18bacb3a531de6c64e6ccf4f01abc22dc47c3a378ecc
4
+ data.tar.gz: b48d6d62205280be48ec415bc5b67af3ae5a5ee7afe3581a707064fa46f5986f
5
5
  SHA512:
6
- metadata.gz: d40d6f6934605ae6e261af6ddf06161c303f3db1abc816bbdd6fa233a68c9fc9f643e8043f582f4240a0d9498646aba2ce3411dcc22dc8b17b9b6e121b970bcd
7
- data.tar.gz: e69239f8a8578eee50c6a54ff6e6b733e1c052e60bff7871a1fa3df975f8fe20e30c0589b75e207267c98cf6e709d18a333b84ab24c2b9bf72df5b966296b830
6
+ metadata.gz: f101686b41f0c201d3bf0414f7aa1529450ca79ffed19e272875c48ba617bf0a9933876510715f3a65d016af3f4ed7ebeb179a932489dfe7c074a0a3465fba3a
7
+ data.tar.gz: 3b4dcc7ce851136b62cb3fe534fa38746da07c834d25b19a56927dfabe01f0be4a1e3e5ba95434fce80cc43c566244854b08eb0b6fbb7f14cb1dce33d8a2b18f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.18.0 - 2019/05/29
2
+
3
+ * ⚠️ [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).*
4
+ In order to be compliant with the the next major release, all conditional :if/:unless procs must be augmented to take in three arguments instead of two. i.e. `(obj, options)` to `(field_name, obj, options)`.
5
+
1
6
  ## 0.17.0 - 2019/05/23
2
7
  * 🐛 [BUGFIX] Fixing view: :identifier including non-identifier fields. [#154](https://github.com/procore/blueprinter/pull/154). Thanks to [@AllPurposeName](https://github.com/AllPurposeName).
3
8
 
data/README.md CHANGED
@@ -581,8 +581,8 @@ Both the `field` and the global Blueprinter Configuration supports `:if` and `:u
581
581
  #### Global Config Setting
582
582
  ```ruby
583
583
  Blueprinter.configure do |config|
584
- config.if = ->(obj, _options) { obj.is_a?(Foo) }
585
- config.unless = ->(obj, _options) { obj.is_a?(Bar) }
584
+ config.if = ->(field_name, obj, _options) { !obj[field_name].nil? }
585
+ config.unless = ->(field_name, obj, _options) { obj[field_name].nil? }
586
586
  end
587
587
  ```
588
588
 
@@ -78,11 +78,11 @@ module Blueprinter
78
78
  # on the Date/DateTime object.
79
79
  # @option options [Symbol,Proc] :if Specifies a method, proc or string to
80
80
  # call to determine if the field should be included (e.g.
81
- # `if: :include_first_name?, or if: Proc.new { |user, options| options[:current_user] == user }).
81
+ # `if: :include_first_name?, or if: Proc.new { |_field_name, user, options| options[:current_user] == user }).
82
82
  # The method, proc or string should return or evaluate to a true or false value.
83
83
  # @option options [Symbol,Proc] :unless Specifies a method, proc or string
84
84
  # to call to determine if the field should be included (e.g.
85
- # `unless: :include_first_name?, or unless: Proc.new { |user, options| options[:current_user] != user }).
85
+ # `unless: :include_first_name?, or unless: Proc.new { |_field_name, user, options| options[:current_user] != user }).
86
86
  # The method, proc or string should return or evaluate to a true or false value.
87
87
  # @yield [object, options] The object and the options passed to render are
88
88
  # also yielded to the block.
@@ -101,14 +101,14 @@ module Blueprinter
101
101
  # # other code
102
102
  # end
103
103
  #
104
- # @example Passing an if proc and unless method..
104
+ # @example Passing an if proc and unless method.
105
105
  # class UserBlueprint < Blueprinter::Base
106
- # def skip_first_name?(user, options)
106
+ # def skip_first_name?(_field_name, user, options)
107
107
  # user.first_name == options[:first_name]
108
108
  # end
109
109
  #
110
110
  # field :first_name, unless: :skip_first_name?
111
- # field :last_name, if: ->(user, options) { user.first_name != options[:first_name] }
111
+ # field :last_name, if: ->(_field_name, user, options) { user.first_name != options[:first_name] }
112
112
  # # other code
113
113
  # end
114
114
  #
@@ -316,15 +316,15 @@ module Blueprinter
316
316
  def self.exclude(field_name)
317
317
  current_view.exclude_field(field_name)
318
318
  end
319
-
319
+
320
320
  # When mixing multiple views under a single view, some fields may required to be excluded from
321
321
  # current view
322
- #
322
+ #
323
323
  # @param [Array<Symbol>] the fields to exclude from the current view.
324
324
  #
325
325
  # @example Excluding mutiple fields from being included into the current view.
326
326
  # view :normal do
327
- # fields :name,:address,:position,
327
+ # fields :name,:address,:position,
328
328
  # :company, :contact
329
329
  # end
330
330
  # view :special do
@@ -335,7 +335,7 @@ module Blueprinter
335
335
  # => [:name, :company, :contact, :birthday, :joining_anniversary]
336
336
  #
337
337
  # @return [Array<Symbol>] an array of field names
338
-
338
+
339
339
  def self.excludes(*field_names)
340
340
  current_view.exclude_fields(field_names)
341
341
  end
@@ -13,9 +13,9 @@ class Blueprinter::Field
13
13
  extractor.extract(method, object, local_options, options)
14
14
  end
15
15
 
16
- def skip?(object, local_options)
17
- return true if if_callable && !if_callable.call(object, local_options)
18
- unless_callable && unless_callable.call(object, local_options)
16
+ def skip?(field_name, object, local_options)
17
+ return true if if_callable && !if_callable.call(field_name, object, local_options)
18
+ unless_callable && unless_callable.call(field_name, object, local_options)
19
19
  end
20
20
 
21
21
  private
@@ -31,6 +31,17 @@ class Blueprinter::Field
31
31
  end
32
32
 
33
33
  def callable_from(condition)
34
+ callable = old_callable_from(condition)
35
+
36
+ if callable && callable.arity == 2
37
+ warn "[DEPRECATION] Blueprinter :#{condition} conditions now expects 3 arguments instead of 2."
38
+ ->(_field_name, obj, options) { callable.call(obj, options) }
39
+ else
40
+ callable
41
+ end
42
+ end
43
+
44
+ def old_callable_from(condition)
34
45
  config = Blueprinter.configuration
35
46
 
36
47
  # Use field-level callable, or when not defined, try global callable
@@ -38,14 +38,14 @@ module Blueprinter
38
38
  ret = { root => data }
39
39
  meta ? ret.merge!(meta: meta) : ret
40
40
  end
41
-
41
+
42
42
  def inherited(subclass)
43
43
  subclass.send(:view_collection).inherit(view_collection)
44
44
  end
45
45
 
46
46
  def object_to_hash(object, view_name:, local_options:)
47
47
  view_collection.fields_for(view_name).each_with_object({}) do |field, hash|
48
- next if field.skip?(object, local_options)
48
+ next if field.skip?(field.name, object, local_options)
49
49
  hash[field.name] = field.extract(object, local_options)
50
50
  end
51
51
  end
@@ -1,3 +1,3 @@
1
1
  module Blueprinter
2
- VERSION = '0.17.0'
2
+ VERSION = '0.18.0'
3
3
  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.17.0
4
+ version: 0.18.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-05-23 00:00:00.000000000 Z
12
+ date: 2019-06-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: factory_bot