Skip to content

Commit

Permalink
Changed the ScopeRegistry and the InstrumentationRegistry to use the
Browse files Browse the repository at this point in the history
PerThreadRegistry module.
  • Loading branch information
wangjohn committed Apr 10, 2013
1 parent 95ac391 commit e12901e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
12 changes: 6 additions & 6 deletions activerecord/lib/active_record/scoping.rb
@@ -1,3 +1,5 @@
require 'active_support/per_thread_registry'

module ActiveRecord
module Scoping
extend ActiveSupport::Concern
Expand Down Expand Up @@ -34,7 +36,7 @@ def populate_with_current_scope_attributes
# 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:
Expand All @@ -48,12 +50,10 @@ def populate_with_current_scope_attributes
# 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]
Expand Down
4 changes: 2 additions & 2 deletions activerecord/test/cases/base_test.rb
Expand Up @@ -1377,9 +1377,9 @@ def test_current_scope_is_reset
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
Expand Down
9 changes: 4 additions & 5 deletions 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
Expand Down Expand Up @@ -190,12 +191,10 @@ def instrumenter
# 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
Expand Down

0 comments on commit e12901e

Please sign in to comment.