Skip to content

Commit

Permalink
Modernize deprecation handling to fix deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sudoremo committed Aug 22, 2024
1 parent 09ed2dd commit 2ff209b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/rails_ops.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

# ---------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_ops/model_mixins/virtual_has_one.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion lib/rails_ops/railtie.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/unit/rails_ops/operation/model_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 2ff209b

Please sign in to comment.