deprecation_toolkit 2.2.2 → 2.2.4

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: 6764813c0b9b8522fa1e755f59e4f3e7137fa229a24e5b96ae05fbcbd53efdc7
4
- data.tar.gz: 5e570bcbf742061e36c5aeb4b1073a3ba546c47e5caefaba2b1d33abaaf1c037
3
+ metadata.gz: 928c5fd8932b5f69fd9a51ea255ff5db6977fedc011c9ff211de0e3d73f4cc4e
4
+ data.tar.gz: f514ee0194329683cad36aa454280acaa0a8ecd84ba02d698b45b7b1c84cf0f8
5
5
  SHA512:
6
- metadata.gz: 9c851ca5d25bdaed7522be6f1736766bd92a66f454993ec060c048fe6f09feb9f28d3d7c608ba248a31492b8c6656782871507d6e9fd138af85e03b53446dda7
7
- data.tar.gz: f8ba1b548b6cde09de40768dce5f2b79ba23dd3bf69620cc6255520efc6fe11c4f8839978d7f0d1ecfa1f0c77307ddf2743cd219d1834ae181f3f762d2f3a80a
6
+ metadata.gz: 65c66a322df4cfcd5977531d5b0fa60221c096d8d36e7e653b2c9f6d571e175d1fa6a868b53d85c63c80e768a115b7813f65494a61697d96a9456c786a4267e9
7
+ data.tar.gz: 149af66da445071b2b586373cffaf03f43d24b59210d102529b70024a8b5c94bdc5d465270ed2e25709e86133ebae43ba43946e4941fe888677c0d9ae1776257
@@ -5,8 +5,54 @@ require "active_support/subscriber"
5
5
  module DeprecationToolkit
6
6
  class DeprecationSubscriber < ActiveSupport::Subscriber
7
7
  class << self
8
- def already_attached?
9
- notifier != nil
8
+ def attach_to(gem_name, subscriber = new, notifier = ActiveSupport::Notifications, inherit_all: false)
9
+ return if already_attached_to?(gem_name)
10
+
11
+ super(gem_name, subscriber, notifier, inherit_all: inherit_all)
12
+ end
13
+
14
+ def detach_from(gem_name, notifier = ActiveSupport::Notifications)
15
+ @namespace = gem_name
16
+ @subscriber = find_attached_subscriber(gem_name)
17
+ @notifier = notifier
18
+
19
+ return unless subscriber
20
+
21
+ subscribers.delete(subscriber)
22
+
23
+ # Remove event subscribers of all existing methods on the class.
24
+ fetch_public_methods(subscriber, true).each do |event|
25
+ remove_event_subscriber(event)
26
+ end
27
+
28
+ @notifier = nil unless any_subscribers_attached?
29
+ end
30
+
31
+ private
32
+
33
+ def already_attached_to?(gem_name)
34
+ subscribers.any? do |subscriber|
35
+ attached_subscriber?(subscriber, gem_name)
36
+ end
37
+ end
38
+
39
+ def any_subscribers_attached?
40
+ subscribers.any? do |subscriber|
41
+ subscriber.is_a?(self)
42
+ end
43
+ end
44
+
45
+ def find_attached_subscriber(gem_name)
46
+ subscribers.find do |attached_subscriber|
47
+ attached_subscriber?(attached_subscriber, gem_name)
48
+ end
49
+ end
50
+
51
+ def attached_subscriber?(subscriber, gem_name)
52
+ subscriber.is_a?(self) &&
53
+ subscriber.patterns.keys.any? do |pattern|
54
+ pattern.end_with?(".#{gem_name}")
55
+ end
10
56
  end
11
57
  end
12
58
 
@@ -15,32 +15,29 @@ module DeprecationToolkit
15
15
  end
16
16
 
17
17
  def write(deprecation_file, deprecations_to_record)
18
- create_deprecation_file(deprecation_file) unless deprecation_file.exist?
18
+ original_deprecations = deprecation_file.exist? ? YAML.load_file(deprecation_file) : {}
19
+ updated_deprecations = original_deprecations.dup
19
20
 
20
- content = YAML.load_file(deprecation_file)
21
-
22
- deprecations_to_record.each do |test, deprecations|
23
- if deprecations.any?
24
- content[test] = deprecations
21
+ deprecations_to_record.each do |test, deprecation_to_record|
22
+ if deprecation_to_record.any?
23
+ updated_deprecations[test] = deprecation_to_record
25
24
  else
26
- content.delete(test)
25
+ updated_deprecations.delete(test)
27
26
  end
28
27
  end
29
28
 
30
- if content.any?
31
- deprecation_file.write(YAML.dump(content))
32
- else
29
+ if updated_deprecations.any?
30
+ if updated_deprecations != original_deprecations
31
+ deprecation_file.dirname.mkpath
32
+ deprecation_file.write(YAML.dump(updated_deprecations.sort.to_h))
33
+ end
34
+ elsif deprecation_file.exist?
33
35
  deprecation_file.delete
34
36
  end
35
37
  end
36
38
 
37
39
  private
38
40
 
39
- def create_deprecation_file(deprecation_file)
40
- deprecation_file.dirname.mkpath
41
- deprecation_file.write(YAML.dump({}))
42
- end
43
-
44
41
  def recorded_deprecations_path(test)
45
42
  deprecation_folder = if Configuration.deprecation_path.is_a?(Proc)
46
43
  Configuration.deprecation_path.call(test_location(test))
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeprecationToolkit
4
- VERSION = "2.2.2"
4
+ VERSION = "2.2.4"
5
5
  end
@@ -16,6 +16,9 @@ module DeprecationToolkit
16
16
  autoload :Raise, "deprecation_toolkit/behaviors/raise"
17
17
  autoload :Record, "deprecation_toolkit/behaviors/record"
18
18
  autoload :CIRecordHelper, "deprecation_toolkit/behaviors/ci_record_helper"
19
+ autoload :DeprecationIntroduced, "deprecation_toolkit/behaviors/raise"
20
+ autoload :DeprecationRemoved, "deprecation_toolkit/behaviors/raise"
21
+ autoload :DeprecationMismatch, "deprecation_toolkit/behaviors/raise"
19
22
  end
20
23
 
21
24
  class << self
@@ -32,8 +35,6 @@ module DeprecationToolkit
32
35
  end
33
36
 
34
37
  def attach_subscriber
35
- return if DeprecationSubscriber.already_attached?
36
-
37
38
  Configuration.attach_to.each do |gem_name|
38
39
  DeprecationSubscriber.attach_to(gem_name)
39
40
  end
@@ -14,6 +14,10 @@ module Minitest
14
14
 
15
15
  require "deprecation_toolkit"
16
16
 
17
+ setup_deprecation_toolkit(options)
18
+ end
19
+
20
+ def setup_deprecation_toolkit(options)
17
21
  if options[:record_deprecations]
18
22
  DeprecationToolkit::Configuration.behavior = DeprecationToolkit::Behaviors::Record
19
23
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deprecation_toolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-23 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activesupport
@@ -53,7 +53,7 @@ licenses:
53
53
  - MIT
54
54
  metadata:
55
55
  homepage_uri: https://github.com/shopify/deprecation_toolkit
56
- source_code_uri: https://github.com/Shopify/deprecation_toolkit/tree/v2.2.2
56
+ source_code_uri: https://github.com/Shopify/deprecation_toolkit/tree/v2.2.4
57
57
  changelog_uri: https://github.com/Shopify/deprecation_toolkit/blob/main/CHANGELOG.md
58
58
  allowed_push_host: https://rubygems.org
59
59
  rdoc_options: []
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  - !ruby/object:Gem::Version
71
71
  version: '0'
72
72
  requirements: []
73
- rubygems_version: 3.6.2
73
+ rubygems_version: 3.7.1
74
74
  specification_version: 4
75
75
  summary: Deprecation Toolkit around ActiveSupport::Deprecation
76
76
  test_files: []