From e5ef3abdd2336c34cd853a1f845f79b8b19fbb1b Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 13 Apr 2013 17:08:00 +0200 Subject: hides the per thread registry instance, and caches singleton methods Existing code was delegating to the instance with delegate macro calls, or invoking the instance method to reach the object and call its instance methods. But the point is to have a clean class-level interface where the thread local instance is hidden in the implementation. References #11c6973. References #10198. --- activerecord/lib/active_record/scoping.rb | 6 +----- activerecord/test/cases/base_test.rb | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/scoping.rb b/activerecord/lib/active_record/scoping.rb index 6ab36a23a7..0cf3d59985 100644 --- a/activerecord/lib/active_record/scoping.rb +++ b/activerecord/lib/active_record/scoping.rb @@ -36,7 +36,7 @@ module ActiveRecord # to get the current_scope for the +Board+ model, then you would use the # following code: # - # registry = ActiveRecord::Scoping::ScopeRegistry.instance + # registry = ActiveRecord::Scoping::ScopeRegistry # registry.set_value_for(:current_scope, "Board", some_new_scope) # # Now when you run: @@ -52,10 +52,6 @@ module ActiveRecord class ScopeRegistry # :nodoc: extend ActiveSupport::PerThreadRegistry - class << self - delegate :value_for, :set_value_for, to: :instance - end - VALID_SCOPE_TYPES = [:current_scope, :ignore_default_scope] def initialize diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 83fc0b48f9..bd568af06a 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1377,9 +1377,9 @@ class BasicsTest < ActiveRecord::TestCase UnloadablePost.send(:current_scope=, UnloadablePost.all) UnloadablePost.unloadable - assert_not_nil ActiveRecord::Scoping::ScopeRegistry.instance.value_for(:current_scope, "UnloadablePost") + assert_not_nil ActiveRecord::Scoping::ScopeRegistry.value_for(:current_scope, "UnloadablePost") ActiveSupport::Dependencies.remove_unloadable_constants! - assert_nil ActiveRecord::Scoping::ScopeRegistry.instance.value_for(:current_scope, "UnloadablePost") + assert_nil ActiveRecord::Scoping::ScopeRegistry.value_for(:current_scope, "UnloadablePost") ensure Object.class_eval{ remove_const :UnloadablePost } if defined?(UnloadablePost) end -- cgit v1.2.3