Skip to content

Commit 6c9fcad

Browse files
committed
Use a custom deprecator instead of ActiveSupport::Deprecation directly
1 parent e6162f5 commit 6c9fcad

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

Diff for: lib/active_resource.rb

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ module ActiveResource
4242
autoload :InheritingHash
4343
autoload :Validations
4444
autoload :Collection
45+
46+
def self.deprecator
47+
@deprecator ||= if ActiveSupport::VERSION::STRING >= '7.2'
48+
ActiveSupport::Deprecation.new(VERSION::STRING, 'ActiveResource')
49+
else
50+
ActiveSupport::Deprecation
51+
end
52+
end
4553
end
4654

4755
require "active_resource/railtie" if defined?(Rails.application)

Diff for: lib/active_resource/railtie.rb

+4
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,9 @@ class Railtie < Rails::Railtie
2121
app.config.active_job.custom_serializers << ActiveResource::ActiveJobSerializer
2222
end
2323
end
24+
25+
initializer "active_resource.deprecator" do |app|
26+
app.deprecators[:active_resource] = ActiveResource.deprecator
27+
end
2428
end
2529
end

Diff for: lib/active_resource/validations.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ def from_json(json, save_cache = false)
5757
errors = decoded["errors"] || {}
5858
if errors.kind_of?(Array)
5959
# 3.2.1-style with array of strings
60-
ActiveSupport::Deprecation.warn("Returning errors as an array of strings is deprecated.")
60+
ActiveResource.deprecator.warn("Returning errors as an array of strings is deprecated.")
6161
from_array errors, save_cache
6262
else
6363
# 3.2.2+ style
6464
from_hash errors, save_cache
6565
end
6666
else
6767
# <3.2-style respond_with - lacks 'errors' key
68-
ActiveSupport::Deprecation.warn('Returning errors as a hash without a root "errors" key is deprecated.')
68+
ActiveResource.deprecator.warn('Returning errors as a hash without a root "errors" key is deprecated.')
6969
from_hash decoded, save_cache
7070
end
7171
end

0 commit comments

Comments
 (0)