Skip to content

Commit b25477d

Browse files
committed
Introduce ActiveSupport Deprecator
Refs. rails/rails#47354
1 parent 65e5e8e commit b25477d

14 files changed

+31
-22
lines changed

lib/carrierwave.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'active_support/core_ext/object/try'
44
require 'active_support/core_ext/class/attribute'
55
require 'active_support/concern'
6+
require 'active_support/deprecation'
67

78
module CarrierWave
89

@@ -21,6 +22,10 @@ def clean_cached_files!(seconds=60*60*24)
2122
def tmp_path
2223
@tmp_path ||= File.expand_path(File.join('..', 'tmp'), root)
2324
end
25+
26+
def deprecator
27+
@deprecator ||= ActiveSupport::Deprecation.new("#{CarrierWave::VERSION.split('.')[0].to_i + 1}.0", "CarrierWave")
28+
end
2429
end
2530

2631
end
@@ -64,6 +69,10 @@ class Railtie < Rails::Railtie
6469
end
6570
end
6671

72+
initializer "carrierwave.deprecator" do |app|
73+
app.deprecators[:carrierwave] = CarrierWave.deprecator
74+
end
75+
6776
config.before_eager_load do
6877
CarrierWave::Storage::Fog.eager_load
6978
end

lib/carrierwave/processing/rmagick.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ def create_info_block(options)
408408
proc do |img|
409409
options.each do |k, v|
410410
if v.is_a?(String) && (matches = v.match(/^["'](.+)["']/))
411-
ActiveSupport::Deprecation.warn "Passing quoted strings like #{v} to #manipulate! is deprecated, pass them without quoting."
411+
CarrierWave.deprecator.warn "Passing quoted strings like #{v} to #manipulate! is deprecated, pass them without quoting."
412412
v = matches[1]
413413
end
414414
img.public_send(:"#{k}=", v)

lib/carrierwave/uploader/cache.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ def cache_stored_file!
9191
end
9292

9393
def sanitized_file
94-
ActiveSupport::Deprecation.warn('#sanitized_file is deprecated, use #file instead.')
9594
file
9695
end
96+
CarrierWave.deprecator.deprecate_methods(self, sanitized_file: :file)
9797

9898
##
9999
# Returns a String which uniquely identifies the currently cached file for later retrieval

lib/carrierwave/uploader/configuration.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,19 +157,19 @@ def #{name}
157157
def add_deprecated_config(name)
158158
class_eval <<-RUBY, __FILE__, __LINE__ + 1
159159
def self.#{name}(value=nil)
160-
ActiveSupport::Deprecation.warn "##{name} is deprecated and has no effect"
160+
CarrierWave.deprecator.warn "##{name} is deprecated and has no effect"
161161
end
162162
163163
def self.#{name}=(value)
164-
ActiveSupport::Deprecation.warn "##{name} is deprecated and has no effect"
164+
CarrierWave.deprecator.warn "##{name} is deprecated and has no effect"
165165
end
166166
167167
def #{name}=(value)
168-
ActiveSupport::Deprecation.warn "##{name} is deprecated and has no effect"
168+
CarrierWave.deprecator.warn "##{name} is deprecated and has no effect"
169169
end
170170
171171
def #{name}
172-
ActiveSupport::Deprecation.warn "##{name} is deprecated and has no effect"
172+
CarrierWave.deprecator.warn "##{name} is deprecated and has no effect"
173173
end
174174
RUBY
175175
end

lib/carrierwave/uploader/content_type_allowlist.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def content_type_allowlist
3636
def check_content_type_allowlist!(new_file)
3737
allowlist = content_type_allowlist
3838
if !allowlist && respond_to?(:content_type_whitelist) && content_type_whitelist
39-
ActiveSupport::Deprecation.warn "#content_type_whitelist is deprecated, use #content_type_allowlist instead." unless instance_variable_defined?(:@content_type_whitelist_warned)
39+
CarrierWave.deprecator.warn "#content_type_whitelist is deprecated, use #content_type_allowlist instead." unless instance_variable_defined?(:@content_type_whitelist_warned)
4040
@content_type_whitelist_warned = true
4141
allowlist = content_type_whitelist
4242
end

lib/carrierwave/uploader/content_type_denylist.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ def content_type_denylist
3636
def check_content_type_denylist!(new_file)
3737
denylist = content_type_denylist
3838
if !denylist && respond_to?(:content_type_blacklist) && content_type_blacklist
39-
ActiveSupport::Deprecation.warn "#content_type_blacklist is deprecated, use #content_type_denylist instead." unless instance_variable_defined?(:@content_type_blacklist_warned)
39+
CarrierWave.deprecator.warn "#content_type_blacklist is deprecated, use #content_type_denylist instead." unless instance_variable_defined?(:@content_type_blacklist_warned)
4040
@content_type_blacklist_warned = true
4141
denylist = content_type_blacklist
4242
end
4343

4444
return unless denylist
4545

46-
ActiveSupport::Deprecation.warn "Use of #content_type_denylist is deprecated for the security reason, use #content_type_allowlist instead to explicitly state what are safe to accept" unless instance_variable_defined?(:@content_type_denylist_warned)
46+
CarrierWave.deprecator.warn "Use of #content_type_denylist is deprecated for the security reason, use #content_type_allowlist instead to explicitly state what are safe to accept" unless instance_variable_defined?(:@content_type_denylist_warned)
4747
@content_type_denylist_warned = true
4848

4949
content_type = new_file.content_type

lib/carrierwave/uploader/extension_allowlist.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def extension_allowlist
3939
def check_extension_allowlist!(new_file)
4040
allowlist = extension_allowlist
4141
if !allowlist && respond_to?(:extension_whitelist) && extension_whitelist
42-
ActiveSupport::Deprecation.warn "#extension_whitelist is deprecated, use #extension_allowlist instead." unless instance_variable_defined?(:@extension_whitelist_warned)
42+
CarrierWave.deprecator.warn "#extension_whitelist is deprecated, use #extension_allowlist instead." unless instance_variable_defined?(:@extension_whitelist_warned)
4343
@extension_whitelist_warned = true
4444
allowlist = extension_whitelist
4545
end

lib/carrierwave/uploader/extension_denylist.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ def extension_denylist
3939
def check_extension_denylist!(new_file)
4040
denylist = extension_denylist
4141
if !denylist && respond_to?(:extension_blacklist) && extension_blacklist
42-
ActiveSupport::Deprecation.warn "#extension_blacklist is deprecated, use #extension_denylist instead." unless instance_variable_defined?(:@extension_blacklist_warned)
42+
CarrierWave.deprecator.warn "#extension_blacklist is deprecated, use #extension_denylist instead." unless instance_variable_defined?(:@extension_blacklist_warned)
4343
@extension_blacklist_warned = true
4444
denylist = extension_blacklist
4545
end
4646

4747
return unless denylist
4848

49-
ActiveSupport::Deprecation.warn "Use of #extension_denylist is deprecated for the security reason, use #extension_allowlist instead to explicitly state what are safe to accept" unless instance_variable_defined?(:@extension_denylist_warned)
49+
CarrierWave.deprecator.warn "Use of #extension_denylist is deprecated for the security reason, use #extension_allowlist instead to explicitly state what are safe to accept" unless instance_variable_defined?(:@extension_denylist_warned)
5050
@extension_denylist_warned = true
5151

5252
extension = new_file.extension.to_s

spec/orm/activerecord_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def extension_allowlist
278278

279279
context 'when validating denylist integrity' do
280280
before do
281-
allow(ActiveSupport::Deprecation).to receive(:warn).with(/#extension_denylist/)
281+
allow(CarrierWave.deprecator).to receive(:warn).with(/#extension_denylist/)
282282
@uploader.class_eval do
283283
def extension_denylist
284284
%w(jpg)
@@ -1327,7 +1327,7 @@ def extension_allowlist
13271327

13281328
context 'when validating denylist integrity' do
13291329
before do
1330-
allow(ActiveSupport::Deprecation).to receive(:warn).with(/#extension_denylist/)
1330+
allow(CarrierWave.deprecator).to receive(:warn).with(/#extension_denylist/)
13311331
@uploader.class_eval do
13321332
def extension_denylist
13331333
%w(jpg)

spec/processing/rmagick_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,13 @@
226226

227227
it 'shows deprecation but still accepts strings enclosed with double quotes' do
228228
expect_any_instance_of(::Magick::Image::Info).to receive(:size=).once.with("200x200")
229-
expect(ActiveSupport::Deprecation).to receive(:warn).with(any_args)
229+
expect(CarrierWave.deprecator).to receive(:warn).with(any_args)
230230
instance.manipulate! :read => {:size => %{"200x200"}}
231231
end
232232

233233
it 'shows deprecation but still accepts strings enclosed with single quotes' do
234234
expect_any_instance_of(::Magick::Image::Info).to receive(:size=).once.with("200x200")
235-
expect(ActiveSupport::Deprecation).to receive(:warn).with(any_args)
235+
expect(CarrierWave.deprecator).to receive(:warn).with(any_args)
236236
instance.manipulate! :read => {:size => %{'200x200'}}
237237
end
238238

0 commit comments

Comments
 (0)