diff options
| author | wangjohn <wangjohn@mit.edu> | 2013-04-09 19:20:49 -0400 |
|---|---|---|
| committer | wangjohn <wangjohn@mit.edu> | 2013-04-09 22:27:32 -0400 |
| commit | e12901e4235d1ece2a17c5419f4420f1931cc6a4 (patch) | |
| tree | 5bcd2ef9f09cc031f54f9475ec28c9f0e6b4c4e1 | |
| parent | 95ac3913ee24efa1c5a9789963697aaa6e5b32b7 (diff) | |
| download | rails-e12901e4235d1ece2a17c5419f4420f1931cc6a4.tar.gz rails-e12901e4235d1ece2a17c5419f4420f1931cc6a4.tar.bz2 rails-e12901e4235d1ece2a17c5419f4420f1931cc6a4.zip | |
Changed the ScopeRegistry and the InstrumentationRegistry to use the
PerThreadRegistry module.
| -rw-r--r-- | activerecord/lib/active_record/scoping.rb | 12 | ||||
| -rw-r--r-- | activerecord/test/cases/base_test.rb | 4 | ||||
| -rw-r--r-- | activesupport/lib/active_support/notifications.rb | 9 |
3 files changed, 12 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/scoping.rb b/activerecord/lib/active_record/scoping.rb index f108ab0fe0..6ab36a23a7 100644 --- a/activerecord/lib/active_record/scoping.rb +++ b/activerecord/lib/active_record/scoping.rb @@ -1,3 +1,5 @@ +require 'active_support/per_thread_registry' + module ActiveRecord module Scoping extend ActiveSupport::Concern @@ -34,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.current + # registry = ActiveRecord::Scoping::ScopeRegistry.instance # registry.set_value_for(:current_scope, "Board", some_new_scope) # # Now when you run: @@ -48,12 +50,10 @@ module ActiveRecord # ActiveRecord::Scoping::ScopeRegistry.set_value_for(:current_scope, # "Board", some_new_scope) class ScopeRegistry # :nodoc: - class << self - delegate :value_for, :set_value_for, to: :current + extend ActiveSupport::PerThreadRegistry - def current - Thread.current["scope_registry"] ||= new - end + class << self + delegate :value_for, :set_value_for, to: :instance end VALID_SCOPE_TYPES = [:current_scope, :ignore_default_scope] diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index e57dbd5a09..83fc0b48f9 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.current.value_for(:current_scope, "UnloadablePost") + assert_not_nil ActiveRecord::Scoping::ScopeRegistry.instance.value_for(:current_scope, "UnloadablePost") ActiveSupport::Dependencies.remove_unloadable_constants! - assert_nil ActiveRecord::Scoping::ScopeRegistry.current.value_for(:current_scope, "UnloadablePost") + assert_nil ActiveRecord::Scoping::ScopeRegistry.instance.value_for(:current_scope, "UnloadablePost") ensure Object.class_eval{ remove_const :UnloadablePost } if defined?(UnloadablePost) end diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb index ab2bb5fafe..5c985601f4 100644 --- a/activesupport/lib/active_support/notifications.rb +++ b/activesupport/lib/active_support/notifications.rb @@ -1,5 +1,6 @@ require 'active_support/notifications/instrumenter' require 'active_support/notifications/fanout' +require 'active_support/per_thread_registry' module ActiveSupport # = Notifications @@ -190,12 +191,10 @@ module ActiveSupport # The instrumenters for multiple notifiers are held in a single instance of # this class. class InstrumentationRegistry # :nodoc: - class << self - delegate :instrumenter_for, to: :current + extend ActiveSupport::PerThreadRegistry - def current - Thread.current[:instrumentation_registry] ||= new - end + class << self + delegate :instrumenter_for, to: :instance end def initialize |
