deprecation_toolkit 1.0.3 → 1.1.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
  SHA1:
3
- metadata.gz: e01e1ccdad76b3a084e7c5ad013fea98f28fc959
4
- data.tar.gz: af5cd6abbb05a4ee4ea615b424d00be914b57567
3
+ metadata.gz: 4a142310e36ffb312bd50a257a82260477fc8940
4
+ data.tar.gz: ca2b082fddc00a195c72e081eac71512d358b7dd
5
5
  SHA512:
6
- metadata.gz: afd8e6cc37cd0bd0e025334752f13bb389a191531a8e0a26de2ecc09f1e9f7086cf796cd56e3a1dd8e1154dbd236c99de913c37aba4f248112b8c335c330e5ea
7
- data.tar.gz: c24ee0952676a10d928125b1145e293bc5a72a59cf5d6a1624ab1264aa6e29f0913618289e40720c0edd16e0f83e61988aa92febf0457d2973a5d6253d44cbce
6
+ metadata.gz: '038a0936b7029bd2b73b557fa0a43ce6d4b22dfdb92bb98ca9d1c06dd5084528f74809244944b717dbcc41cecde1cba3b358b707fece9a6d62fa3e88b9a96c57'
7
+ data.tar.gz: e2af9e16220b684ca29b79426918aed40c7cdb79ca90f85a72f0a9f7185dab4c21bb15d9cd279c322ccf78ad64f72d2e16462a6fa5abcc0d02e1c5b263781684
data/CHANGELOG.md CHANGED
@@ -3,6 +3,11 @@
3
3
  ## master (unreleased)
4
4
  ### Bug fixes
5
5
 
6
+ ## 1.1.0 (2018-11-13)
7
+ ### New Features
8
+ * [#28](https://github.com/Shopify/deprecation_toolkit/pull/28): `Configuration.allowed_deprecations now accepts Procs.
9
+ This is useful if you need to whitelist deprecations based on the caller.
10
+
6
11
  ## 1.0.3 (2018-10-25)
7
12
  ### Bug fixes
8
13
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- deprecation_toolkit (1.0.3)
4
+ deprecation_toolkit (1.1.0)
5
5
  activesupport (>= 4.2)
6
6
 
7
7
  GEM
@@ -13,7 +13,7 @@ GEM
13
13
  minitest (~> 5.1)
14
14
  tzinfo (~> 1.1)
15
15
  ast (2.4.0)
16
- concurrent-ruby (1.0.5)
16
+ concurrent-ruby (1.1.3)
17
17
  i18n (1.1.1)
18
18
  concurrent-ruby (~> 1.0)
19
19
  jaro_winkler (1.5.1)
@@ -50,4 +50,4 @@ DEPENDENCIES
50
50
  rubocop
51
51
 
52
52
  BUNDLED WITH
53
- 1.16.6
53
+ 1.17.1
data/README.md CHANGED
@@ -73,7 +73,7 @@ DeprecationToolkit::Configuration.behavior = StatsdBehavior
73
73
 
74
74
  ### 🔨 `#DeprecationToolkit::Configuration#allowed_deprecations`
75
75
 
76
- You can ignore some deprecations using `allowed_deprecations`. `allowed_deprecations` accepts an array of Regexp.
76
+ You can ignore some deprecations using `allowed_deprecations`. `allowed_deprecations` accepts an array of Regexp and Procs.
77
77
 
78
78
  Whenever a deprecation matches one of the regex, it is ignored.
79
79
 
@@ -83,6 +83,19 @@ DeprecationToolkit::Configuration.allowed_deprecations = [/Hello World/]
83
83
  ActiveSupport::Deprecation.warn('Hello World') # ignored by Deprecation Toolkit
84
84
  ```
85
85
 
86
+ When passing procs, each proc will get passed the deprecation message and the callstack.
87
+ This is useful if you want to whitelist deprecations based on the caller.
88
+
89
+ ```ruby
90
+ DeprecationToolkit::Configuration.allowed_deprecations = [
91
+ ->(message, stack) { message ~= 'Foo' && stack.first.label == 'method_triggering_deprecation' }
92
+ ]
93
+
94
+ def method_triggering_deprecation
95
+ ActiveSupport::Deprecation.warn('Foo') # Ignored by the the DeprecationToolkit
96
+ end
97
+ ```
98
+
86
99
  ### 🔨 `#DeprecationToolkit::Configuration#warnings_treated_as_deprecation`
87
100
 
88
101
  Most gems don't use `ActiveSupport::Deprecation` to deprecate their code but instead just use `Kernel#warn` to output
@@ -22,6 +22,8 @@ module DeprecationToolkit
22
22
  end
23
23
 
24
24
  def self.attach_subscriber
25
+ return if DeprecationSubscriber.already_attached?
26
+
25
27
  Configuration.attach_to.each do |gem_name|
26
28
  DeprecationSubscriber.attach_to gem_name
27
29
  end
@@ -4,16 +4,23 @@ require "active_support/subscriber"
4
4
 
5
5
  module DeprecationToolkit
6
6
  class DeprecationSubscriber < ActiveSupport::Subscriber
7
+ def self.already_attached?
8
+ notifier != nil
9
+ end
10
+
7
11
  def deprecation(event)
8
12
  message = event.payload[:message]
9
13
 
10
- Collector.collect(message) unless deprecation_allowed?(message)
14
+ Collector.collect(message) unless deprecation_allowed?(event.payload)
11
15
  end
12
16
 
13
17
  private
14
18
 
15
- def deprecation_allowed?(message)
16
- Configuration.allowed_deprecations.any? { |regex| regex =~ message }
19
+ def deprecation_allowed?(payload)
20
+ allowed_deprecations, procs = Configuration.allowed_deprecations.partition { |el| el.is_a?(Regexp) }
21
+
22
+ allowed_deprecations.any? { |regex| regex =~ payload[:message] } ||
23
+ procs.any? { |proc| proc.call(payload[:message], payload[:callstack]) }
17
24
  end
18
25
  end
19
26
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeprecationToolkit
4
- VERSION = "1.0.3"
4
+ VERSION = "1.1.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deprecation_toolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-25 00:00:00.000000000 Z
11
+ date: 2018-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport