diff --git a/lib/carrierwave.rb b/lib/carrierwave.rb index 89f2efbde..f02b831e0 100644 --- a/lib/carrierwave.rb +++ b/lib/carrierwave.rb @@ -3,6 +3,7 @@ require 'active_support/core_ext/object/try' require 'active_support/core_ext/class/attribute' require 'active_support/concern' +require 'active_support/deprecation' module CarrierWave @@ -21,6 +22,10 @@ def clean_cached_files!(seconds=60*60*24) def tmp_path @tmp_path ||= File.expand_path(File.join('..', 'tmp'), root) end + + def deprecator + @deprecator ||= ActiveSupport::Deprecation.new("#{CarrierWave::VERSION.split('.')[0].to_i + 1}.0", "CarrierWave") + end end end @@ -64,6 +69,10 @@ class Railtie < Rails::Railtie end end + initializer "carrierwave.deprecator" do |app| + app.deprecators[:carrierwave] = CarrierWave.deprecator + end + config.before_eager_load do CarrierWave::Storage::Fog.eager_load end diff --git a/lib/carrierwave/processing/rmagick.rb b/lib/carrierwave/processing/rmagick.rb index 3f8a75065..ed753e870 100644 --- a/lib/carrierwave/processing/rmagick.rb +++ b/lib/carrierwave/processing/rmagick.rb @@ -408,7 +408,7 @@ def create_info_block(options) proc do |img| options.each do |k, v| if v.is_a?(String) && (matches = v.match(/^["'](.+)["']/)) - ActiveSupport::Deprecation.warn "Passing quoted strings like #{v} to #manipulate! is deprecated, pass them without quoting." + CarrierWave.deprecator.warn "Passing quoted strings like #{v} to #manipulate! is deprecated, pass them without quoting." v = matches[1] end img.public_send(:"#{k}=", v) diff --git a/lib/carrierwave/uploader/cache.rb b/lib/carrierwave/uploader/cache.rb index 28f2f77e1..36cab2b3f 100644 --- a/lib/carrierwave/uploader/cache.rb +++ b/lib/carrierwave/uploader/cache.rb @@ -91,9 +91,9 @@ def cache_stored_file! end def sanitized_file - ActiveSupport::Deprecation.warn('#sanitized_file is deprecated, use #file instead.') file end + CarrierWave.deprecator.deprecate_methods(self, sanitized_file: :file) ## # Returns a String which uniquely identifies the currently cached file for later retrieval diff --git a/lib/carrierwave/uploader/configuration.rb b/lib/carrierwave/uploader/configuration.rb index de1c9fc22..dce36306e 100644 --- a/lib/carrierwave/uploader/configuration.rb +++ b/lib/carrierwave/uploader/configuration.rb @@ -157,19 +157,19 @@ def #{name} def add_deprecated_config(name) class_eval <<-RUBY, __FILE__, __LINE__ + 1 def self.#{name}(value=nil) - ActiveSupport::Deprecation.warn "##{name} is deprecated and has no effect" + CarrierWave.deprecator.warn "##{name} is deprecated and has no effect" end def self.#{name}=(value) - ActiveSupport::Deprecation.warn "##{name} is deprecated and has no effect" + CarrierWave.deprecator.warn "##{name} is deprecated and has no effect" end def #{name}=(value) - ActiveSupport::Deprecation.warn "##{name} is deprecated and has no effect" + CarrierWave.deprecator.warn "##{name} is deprecated and has no effect" end def #{name} - ActiveSupport::Deprecation.warn "##{name} is deprecated and has no effect" + CarrierWave.deprecator.warn "##{name} is deprecated and has no effect" end RUBY end diff --git a/lib/carrierwave/uploader/content_type_allowlist.rb b/lib/carrierwave/uploader/content_type_allowlist.rb index 0a6d69947..1c8f22f1d 100644 --- a/lib/carrierwave/uploader/content_type_allowlist.rb +++ b/lib/carrierwave/uploader/content_type_allowlist.rb @@ -36,7 +36,7 @@ def content_type_allowlist def check_content_type_allowlist!(new_file) allowlist = content_type_allowlist if !allowlist && respond_to?(:content_type_whitelist) && content_type_whitelist - ActiveSupport::Deprecation.warn "#content_type_whitelist is deprecated, use #content_type_allowlist instead." unless instance_variable_defined?(:@content_type_whitelist_warned) + CarrierWave.deprecator.warn "#content_type_whitelist is deprecated, use #content_type_allowlist instead." unless instance_variable_defined?(:@content_type_whitelist_warned) @content_type_whitelist_warned = true allowlist = content_type_whitelist end diff --git a/lib/carrierwave/uploader/content_type_denylist.rb b/lib/carrierwave/uploader/content_type_denylist.rb index e76991465..7164b55d3 100644 --- a/lib/carrierwave/uploader/content_type_denylist.rb +++ b/lib/carrierwave/uploader/content_type_denylist.rb @@ -36,14 +36,14 @@ def content_type_denylist def check_content_type_denylist!(new_file) denylist = content_type_denylist if !denylist && respond_to?(:content_type_blacklist) && content_type_blacklist - ActiveSupport::Deprecation.warn "#content_type_blacklist is deprecated, use #content_type_denylist instead." unless instance_variable_defined?(:@content_type_blacklist_warned) + CarrierWave.deprecator.warn "#content_type_blacklist is deprecated, use #content_type_denylist instead." unless instance_variable_defined?(:@content_type_blacklist_warned) @content_type_blacklist_warned = true denylist = content_type_blacklist end return unless denylist - 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) + 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) @content_type_denylist_warned = true content_type = new_file.content_type diff --git a/lib/carrierwave/uploader/extension_allowlist.rb b/lib/carrierwave/uploader/extension_allowlist.rb index 0c0bdacd1..4a8e6f40b 100644 --- a/lib/carrierwave/uploader/extension_allowlist.rb +++ b/lib/carrierwave/uploader/extension_allowlist.rb @@ -39,7 +39,7 @@ def extension_allowlist def check_extension_allowlist!(new_file) allowlist = extension_allowlist if !allowlist && respond_to?(:extension_whitelist) && extension_whitelist - ActiveSupport::Deprecation.warn "#extension_whitelist is deprecated, use #extension_allowlist instead." unless instance_variable_defined?(:@extension_whitelist_warned) + CarrierWave.deprecator.warn "#extension_whitelist is deprecated, use #extension_allowlist instead." unless instance_variable_defined?(:@extension_whitelist_warned) @extension_whitelist_warned = true allowlist = extension_whitelist end diff --git a/lib/carrierwave/uploader/extension_denylist.rb b/lib/carrierwave/uploader/extension_denylist.rb index 738e1d876..3774117c4 100644 --- a/lib/carrierwave/uploader/extension_denylist.rb +++ b/lib/carrierwave/uploader/extension_denylist.rb @@ -39,14 +39,14 @@ def extension_denylist def check_extension_denylist!(new_file) denylist = extension_denylist if !denylist && respond_to?(:extension_blacklist) && extension_blacklist - ActiveSupport::Deprecation.warn "#extension_blacklist is deprecated, use #extension_denylist instead." unless instance_variable_defined?(:@extension_blacklist_warned) + CarrierWave.deprecator.warn "#extension_blacklist is deprecated, use #extension_denylist instead." unless instance_variable_defined?(:@extension_blacklist_warned) @extension_blacklist_warned = true denylist = extension_blacklist end return unless denylist - 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) + 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) @extension_denylist_warned = true extension = new_file.extension.to_s diff --git a/spec/orm/activerecord_spec.rb b/spec/orm/activerecord_spec.rb index 1e34dc8df..535656e42 100644 --- a/spec/orm/activerecord_spec.rb +++ b/spec/orm/activerecord_spec.rb @@ -278,7 +278,7 @@ def extension_allowlist context 'when validating denylist integrity' do before do - allow(ActiveSupport::Deprecation).to receive(:warn).with(/#extension_denylist/) + allow(CarrierWave.deprecator).to receive(:warn).with(/#extension_denylist/) @uploader.class_eval do def extension_denylist %w(jpg) @@ -1327,7 +1327,7 @@ def extension_allowlist context 'when validating denylist integrity' do before do - allow(ActiveSupport::Deprecation).to receive(:warn).with(/#extension_denylist/) + allow(CarrierWave.deprecator).to receive(:warn).with(/#extension_denylist/) @uploader.class_eval do def extension_denylist %w(jpg) diff --git a/spec/processing/rmagick_spec.rb b/spec/processing/rmagick_spec.rb index c3fb97788..a73edf367 100644 --- a/spec/processing/rmagick_spec.rb +++ b/spec/processing/rmagick_spec.rb @@ -226,13 +226,13 @@ it 'shows deprecation but still accepts strings enclosed with double quotes' do expect_any_instance_of(::Magick::Image::Info).to receive(:size=).once.with("200x200") - expect(ActiveSupport::Deprecation).to receive(:warn).with(any_args) + expect(CarrierWave.deprecator).to receive(:warn).with(any_args) instance.manipulate! :read => {:size => %{"200x200"}} end it 'shows deprecation but still accepts strings enclosed with single quotes' do expect_any_instance_of(::Magick::Image::Info).to receive(:size=).once.with("200x200") - expect(ActiveSupport::Deprecation).to receive(:warn).with(any_args) + expect(CarrierWave.deprecator).to receive(:warn).with(any_args) instance.manipulate! :read => {:size => %{'200x200'}} end diff --git a/spec/uploader/content_type_allowlist_spec.rb b/spec/uploader/content_type_allowlist_spec.rb index fd25a4890..a4b14c87c 100644 --- a/spec/uploader/content_type_allowlist_spec.rb +++ b/spec/uploader/content_type_allowlist_spec.rb @@ -93,7 +93,7 @@ it "uses the whitelist but shows deprecation" do allow(uploader).to receive(:content_type_whitelist).and_return(['image/gif']) - expect(ActiveSupport::Deprecation).to receive(:warn).with('#content_type_whitelist is deprecated, use #content_type_allowlist instead.') + expect(CarrierWave.deprecator).to receive(:warn).with('#content_type_whitelist is deprecated, use #content_type_allowlist instead.') expect { uploader.cache!(bork_file) }.to raise_error(CarrierWave::IntegrityError) diff --git a/spec/uploader/content_type_denylist_spec.rb b/spec/uploader/content_type_denylist_spec.rb index 78b8346a8..f048a2fa4 100644 --- a/spec/uploader/content_type_denylist_spec.rb +++ b/spec/uploader/content_type_denylist_spec.rb @@ -31,7 +31,7 @@ end it "shows up" do - expect(ActiveSupport::Deprecation).to receive(:warn).with('Use of #content_type_denylist is deprecated for the security reason, use #content_type_allowlist instead to explicitly state what are safe to accept') + expect(CarrierWave.deprecator).to receive(:warn).with('Use of #content_type_denylist is deprecated for the security reason, use #content_type_allowlist instead to explicitly state what are safe to accept') expect { uploader.cache!(ruby_file) }.to raise_error(CarrierWave::IntegrityError) end end @@ -75,7 +75,7 @@ it "uses the blacklist but shows deprecation" do allow(uploader).to receive(:content_type_blacklist).and_return(['image/png']) - expect(ActiveSupport::Deprecation).to receive(:warn).with('#content_type_blacklist is deprecated, use #content_type_denylist instead.') + expect(CarrierWave.deprecator).to receive(:warn).with('#content_type_blacklist is deprecated, use #content_type_denylist instead.') expect { uploader.cache!(ruby_file) }.to raise_error(CarrierWave::IntegrityError) end diff --git a/spec/uploader/extension_allowlist_spec.rb b/spec/uploader/extension_allowlist_spec.rb index f86337fed..36138bff5 100644 --- a/spec/uploader/extension_allowlist_spec.rb +++ b/spec/uploader/extension_allowlist_spec.rb @@ -120,7 +120,7 @@ it "uses the whitelist but shows deprecation" do allow(@uploader).to receive(:extension_whitelist).and_return(%w(txt doc xls)) - expect(ActiveSupport::Deprecation).to receive(:warn).with('#extension_whitelist is deprecated, use #extension_allowlist instead.') + expect(CarrierWave.deprecator).to receive(:warn).with('#extension_whitelist is deprecated, use #extension_allowlist instead.') expect { @uploader.cache!(File.open(file_path('test.jpg'))) }.to raise_error(CarrierWave::IntegrityError) diff --git a/spec/uploader/extension_denylist_spec.rb b/spec/uploader/extension_denylist_spec.rb index 6a7160587..861257ce1 100644 --- a/spec/uploader/extension_denylist_spec.rb +++ b/spec/uploader/extension_denylist_spec.rb @@ -32,7 +32,7 @@ end it "shows up" do - expect(ActiveSupport::Deprecation).to receive(:warn).with('Use of #extension_denylist is deprecated for the security reason, use #extension_allowlist instead to explicitly state what are safe to accept') + expect(CarrierWave.deprecator).to receive(:warn).with('Use of #extension_denylist is deprecated for the security reason, use #extension_allowlist instead to explicitly state what are safe to accept') expect { subject }.to raise_error(CarrierWave::IntegrityError) end end @@ -125,7 +125,7 @@ it "uses the blacklist but shows deprecation" do allow(uploader).to receive(:extension_blacklist).and_return(%w(jpg gif png)) - expect(ActiveSupport::Deprecation).to receive(:warn).with('#extension_blacklist is deprecated, use #extension_denylist instead.') + expect(CarrierWave.deprecator).to receive(:warn).with('#extension_blacklist is deprecated, use #extension_denylist instead.') expect { subject }.to raise_error(CarrierWave::IntegrityError) end