Skip to content

Commit

Permalink
ActiveSupport::Deprecator stop using Singleton
Browse files Browse the repository at this point in the history
Followup: #47354

It does a bit more than just giving you a `.instance` method
it also change the behavior of dup and clone, we don't need
any of that, and `.instance` is deprecated anyway.
  • Loading branch information
byroot committed Jun 5, 2023
1 parent 628cdf9 commit 9812641
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 0 additions & 1 deletion activesupport/lib/active_support/deprecation.rb
Expand Up @@ -52,7 +52,6 @@ class Deprecation
require "active_support/core_ext/module/deprecation"
require "concurrent/atomic/thread_local_var"

include Singleton # :nodoc:
include InstanceDelegator
include Behavior
include Reporting
Expand Down
Expand Up @@ -4,13 +4,14 @@ module ActiveSupport
class Deprecation
module InstanceDelegator # :nodoc:
def self.included(base)
base.singleton_class.alias_method(:_instance, :instance)
base.extend(ClassMethods)
base.singleton_class.prepend(OverrideDelegators)
base.public_class_method :new
end

module ClassMethods # :nodoc:
MUTEX = Mutex.new
private_constant :MUTEX

def include(included_module)
included_module.instance_methods.each { |m| method_added(m) }
super
Expand Down Expand Up @@ -40,7 +41,11 @@ def #{method_name}(#{args})

def instance
ActiveSupport.deprecator.warn("ActiveSupport::Deprecation.instance is deprecated (use your own Deprecation object)")
super
_instance
end

def _instance
@_instance ||= MUTEX.synchronize { @_instance ||= new }
end
end

Expand Down

0 comments on commit 9812641

Please sign in to comment.