diff --git a/CHANGELOG.md b/CHANGELOG.md index dc2eeb6..c58e530 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,8 +9,13 @@ Internal reference: `#127570`. +* Modernize deprecation handling to fix the issue where deprecation warnings + would lead to deprecation warnings themselves. + + Internal reference: `#128487`. * Freeze default empty array in `RailsOps::Context#op_chain`. + ## 1.5.5 (2024-03-14) * Add instance method `lock_model_at_build?` to diff --git a/lib/rails_ops.rb b/lib/rails_ops.rb index f40f095..8ca63f1 100644 --- a/lib/rails_ops.rb +++ b/lib/rails_ops.rb @@ -45,6 +45,11 @@ def self.without_authorization(&_block) Thread.current[AUTH_THREAD_STORAGE_KEY] = previous_value end end + + # @private + def self.deprecator + @deprecator ||= ActiveSupport::Deprecation.new('2.0', 'RailsOps') + end end # --------------------------------------------------------------- diff --git a/lib/rails_ops/model_mixins/virtual_has_one.rb b/lib/rails_ops/model_mixins/virtual_has_one.rb index a16bb56..748f877 100644 --- a/lib/rails_ops/model_mixins/virtual_has_one.rb +++ b/lib/rails_ops/model_mixins/virtual_has_one.rb @@ -5,7 +5,7 @@ module VirtualHasOne module ClassMethods def virtual_has_one(name, base_class, required: false, default: nil, type: Integer) - ActiveSupport::Deprecation.warn('virtual_has_one is deprecated and will be removed in a future version.') + RailsOps.deprecator.warn('virtual_has_one is deprecated and will be removed in a future version.') fk = "#{name}_id" attribute fk, type, default: default diff --git a/lib/rails_ops/railtie.rb b/lib/rails_ops/railtie.rb index 7bdbce6..4d96b7f 100644 --- a/lib/rails_ops/railtie.rb +++ b/lib/rails_ops/railtie.rb @@ -1,7 +1,12 @@ module RailsOps # @private class Railtie < Rails::Railtie - initializer 'rails_ops' do |_app| + initializer 'rails_ops' do |app| + # --------------------------------------------------------------- + # Register deprecator + # --------------------------------------------------------------- + app.deprecators[:rails_ops] = RailsOps.deprecator if app + # --------------------------------------------------------------- # Load hookup config eagerly at application startup unless # in development mode. diff --git a/test/unit/rails_ops/operation/model_test.rb b/test/unit/rails_ops/operation/model_test.rb index c54aeef..cf92163 100644 --- a/test/unit/rails_ops/operation/model_test.rb +++ b/test/unit/rails_ops/operation/model_test.rb @@ -50,7 +50,7 @@ def test_virtual_model_name def test_virtual_model_write_attribute cls = Class.new(RailsOps::Operation::Model) do model RailsOps::VirtualModel, 'Example' do - attribute :name, default: 'name' + attribute :name, default: 'name'.freeze end end