blueprinter 0.25.1 → 0.25.2

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: 1ea32b799d411874c19f6fcd40b522e12ac8eca461e3ed518c2ec21d1b2a4980
4
- data.tar.gz: 1a9f5d9ce56d46821047bb693975a310abc044ff7a30c3e3c7ca908bcd81b3c2
3
+ metadata.gz: 9e5e7be1f829035c332a5baa935ef724f52c381bd60f039a20a89368acc7cfde
4
+ data.tar.gz: 7307febc9d3a860aa3b3ffe00a83066b808329a32a3d81dde5a7af7439dc4609
5
5
  SHA512:
6
- metadata.gz: bf07f48a3baaea65428a36c4751a0014f2178c3b391a69f8ad1f6081737454d62caa642b726ca16a8f6b53e83c5ccb61422dc2e470754d37f4c46bb257fea228
7
- data.tar.gz: 5602227efea583382dc8e297151b473a859071cf293908feafdb00d7f50f4753cd53ae17a37e0697a47889543c883a3f0f668b45813ebc4d1bfa23f7c5a29a04
6
+ metadata.gz: 24411ac6c3068b7c08c167e1f91a6e4e25757fd4a32df56f710b0fbe84d07e7507cbdf05eb54645ba3b9b29b8b90c81cede3e68254b254c0523975c9c9236dc0
7
+ data.tar.gz: baef6ae7db2fcc0e6ab9eb4e4c11baf6453ecaf30519462bd6ea5d4dbd5cbd8b1e791f202b2b74e9f15ccc4d265d19828c33b339dc65041916d09351d7729e1f
@@ -1,5 +1,8 @@
1
+ ## 0.25.2 - 2020/11/19
2
+ * 🚀 [FEATURE] Make deprecation behavior configurable (`:silence`, `:stderror`, `:raise`). See [#248](https://github.com/procore/blueprinter/pull/248) thanks to [@mcclayton](https://github.com/mcclayton)
3
+
1
4
  ## 0.25.1 - 2020/8/18
2
- * 🚀 [BUGFIX] Raise Blueprinter::BlueprinterError if Blueprint given is not of class Blueprinter::Base. Before it just raised a generic `undefined method 'prepare'`. See [#233](https://github.com/procore/blueprinter/pull/233) thanks to [@caws](https://github.com/caws)
5
+ * 🐛 [BUGFIX] Raise Blueprinter::BlueprinterError if Blueprint given is not of class Blueprinter::Base. Before it just raised a generic `undefined method 'prepare'`. See [#233](https://github.com/procore/blueprinter/pull/233) thanks to [@caws](https://github.com/caws)
3
6
 
4
7
  ## 0.25.0 - 2020/7/06
5
8
  * 🚀 [FEATURE] Enable default `Blueprinter::Transformer`s to be set in the global configuration. [#222](https://github.com/procore/blueprinter/pull/222). Thanks to [@supremebeing7](https://github.com/supremebeing7).
data/README.md CHANGED
@@ -869,6 +869,33 @@ Output:
869
869
  </details>
870
870
 
871
871
 
872
+ <details>
873
+ <summary>Deprecations</summary>
874
+
875
+ ---
876
+
877
+ When functionality in Blueprinter is invoked, that has been deprecated, the default behavior is to
878
+ write a deprecation notice to stderror.
879
+
880
+ However, deprecations can be configured to report at three different levels:
881
+
882
+ | Key | Result |
883
+ |:-----------------:|:---------------------------------------------------------------:|
884
+ | `:stderr` (Default) | Deprecations will be written to stderror |
885
+ | `:raise` | Deprecations will be raised as `Blueprinter::BlueprinterError`s |
886
+ | `:silence` | Deprecations will be silenced and will not be raised or logged |
887
+
888
+ ### Example:
889
+ ```ruby
890
+ Blueprinter.configure do |config|
891
+ config.deprecations = :raise
892
+ end
893
+ ```
894
+
895
+ ---
896
+ </details>
897
+
898
+
872
899
  <details>
873
900
  <summary>render_as_hash</summary>
874
901
 
@@ -1,5 +1,6 @@
1
1
  require_relative 'blueprinter_error'
2
2
  require_relative 'configuration'
3
+ require_relative 'deprecation'
3
4
  require_relative 'empty_types'
4
5
  require_relative 'extractor'
5
6
  require_relative 'extractors/association_extractor'
@@ -1,10 +1,11 @@
1
1
  module Blueprinter
2
2
  class Configuration
3
- attr_accessor :association_default, :datetime_format, :field_default, :generator, :if, :method, :sort_fields_by, :unless, :extractor_default, :default_transformers
3
+ attr_accessor :association_default, :datetime_format, :deprecations, :field_default, :generator, :if, :method, :sort_fields_by, :unless, :extractor_default, :default_transformers
4
4
 
5
5
  VALID_CALLABLES = %i(if unless).freeze
6
6
 
7
7
  def initialize
8
+ @deprecations = :stderror
8
9
  @association_default = nil
9
10
  @datetime_format = nil
10
11
  @field_default = nil
@@ -0,0 +1,35 @@
1
+ # @api private
2
+ module Blueprinter
3
+ class Deprecation
4
+ class << self
5
+ VALID_BEHAVIORS = %i(silence stderror raise).freeze
6
+ MESSAGE_PREFIX = "[DEPRECATION::WARNING] Blueprinter:".freeze
7
+
8
+ def report(message)
9
+ full_msg = qualified_message(message)
10
+
11
+ case behavior
12
+ when :silence
13
+ # Silence deprecation (noop)
14
+ when :stderror
15
+ warn full_msg
16
+ when :raise
17
+ raise BlueprinterError, full_msg
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def qualified_message(message)
24
+ "#{MESSAGE_PREFIX} #{message}"
25
+ end
26
+
27
+ def behavior
28
+ configured = Blueprinter.configuration.deprecations
29
+ return configured unless !VALID_BEHAVIORS.include?(configured)
30
+
31
+ :stderror
32
+ end
33
+ end
34
+ end
35
+ end
@@ -10,6 +10,8 @@ module Blueprinter
10
10
  private
11
11
 
12
12
  def use_default_value?(value, empty_type)
13
+ return value.nil? unless empty_type
14
+
13
15
  case empty_type
14
16
  when Blueprinter::EMPTY_COLLECTION
15
17
  array_like?(value) && value.empty?
@@ -18,7 +20,10 @@ module Blueprinter
18
20
  when Blueprinter::EMPTY_STRING
19
21
  value.to_s == ""
20
22
  else
21
- value.nil?
23
+ Blueprinter::Deprecation.report(
24
+ "Invalid empty type '#{empty_type}' received. Blueprinter will raise an error in the next major version."\
25
+ "Must be one of [nil, Blueprinter::EMPTY_COLLECTION, Blueprinter::EMPTY_HASH, Blueprinter::EMPTY_STRING]"
26
+ )
22
27
  end
23
28
  end
24
29
  end
@@ -34,7 +34,7 @@ class Blueprinter::Field
34
34
  callable = old_callable_from(condition)
35
35
 
36
36
  if callable && callable.arity == 2
37
- warn "[DEPRECATION] Blueprinter :#{condition} conditions now expects 3 arguments instead of 2."
37
+ Blueprinter::Deprecation.report("`:#{condition}` conditions now expects 3 arguments instead of 2.")
38
38
  ->(_field_name, obj, options) { callable.call(obj, options) }
39
39
  else
40
40
  callable
@@ -1,3 +1,3 @@
1
1
  module Blueprinter
2
- VERSION = '0.25.1'.freeze
2
+ VERSION = '0.25.2'.freeze
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.25.1
4
+ version: 0.25.2
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: 2020-08-18 00:00:00.000000000 Z
12
+ date: 2020-11-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: factory_bot
@@ -197,6 +197,7 @@ files:
197
197
  - lib/blueprinter/base.rb
198
198
  - lib/blueprinter/blueprinter_error.rb
199
199
  - lib/blueprinter/configuration.rb
200
+ - lib/blueprinter/deprecation.rb
200
201
  - lib/blueprinter/empty_types.rb
201
202
  - lib/blueprinter/extractor.rb
202
203
  - lib/blueprinter/extractors/association_extractor.rb