aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-04-09 07:19:29 -0700
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-04-09 07:19:29 -0700
commita74d84bb29a38266ad3de143a4849eed3d3c51fe (patch)
tree463e87b2d02577286533e050f14157148cf8f215 /activerecord
parent821d7bd847eabe201779c39c4d8456434e53f28f (diff)
parenta332712503ec71cea516a6c25fdac85cf44d0adc (diff)
downloadrails-a74d84bb29a38266ad3de143a4849eed3d3c51fe.tar.gz
rails-a74d84bb29a38266ad3de143a4849eed3d3c51fe.tar.bz2
rails-a74d84bb29a38266ad3de143a4849eed3d3c51fe.zip
Merge pull request #10142 from wangjohn/grouping_thread_locals
Delegating the value getter and setters in the ScopeRegistry
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/scoping.rb21
-rw-r--r--activerecord/lib/active_record/scoping/default.rb4
2 files changed, 16 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/scoping.rb b/activerecord/lib/active_record/scoping.rb
index b631730ab3..f108ab0fe0 100644
--- a/activerecord/lib/active_record/scoping.rb
+++ b/activerecord/lib/active_record/scoping.rb
@@ -9,11 +9,11 @@ module ActiveRecord
module ClassMethods
def current_scope #:nodoc:
- ScopeRegistry.current.value_for(:current_scope, base_class.to_s)
+ ScopeRegistry.value_for(:current_scope, base_class.to_s)
end
def current_scope=(scope) #:nodoc:
- ScopeRegistry.current.set_value_for(:current_scope, base_class.to_s, scope)
+ ScopeRegistry.set_value_for(:current_scope, base_class.to_s, scope)
end
end
@@ -41,16 +41,23 @@ module ActiveRecord
#
# registry.value_for(:current_scope, "Board")
#
- # You will obtain whatever was defined in +some_new_scope+.
+ # You will obtain whatever was defined in +some_new_scope+. The +value_for+
+ # and +set_value_for+ methods are delegated to the current +ScopeRegistry+
+ # object, so the above example code can also be called as:
+ #
+ # ActiveRecord::Scoping::ScopeRegistry.set_value_for(:current_scope,
+ # "Board", some_new_scope)
class ScopeRegistry # :nodoc:
- def self.current
- Thread.current["scope_registry"] ||= new
+ class << self
+ delegate :value_for, :set_value_for, to: :current
+
+ def current
+ Thread.current["scope_registry"] ||= new
+ end
end
VALID_SCOPE_TYPES = [:current_scope, :ignore_default_scope]
- attr_accessor :registry
-
def initialize
@registry = Hash.new { |hash, key| hash[key] = {} }
end
diff --git a/activerecord/lib/active_record/scoping/default.rb b/activerecord/lib/active_record/scoping/default.rb
index daee771669..d37d33d552 100644
--- a/activerecord/lib/active_record/scoping/default.rb
+++ b/activerecord/lib/active_record/scoping/default.rb
@@ -120,11 +120,11 @@ module ActiveRecord
end
def ignore_default_scope? # :nodoc:
- ScopeRegistry.current.value_for(:ignore_default_scope, self)
+ ScopeRegistry.value_for(:ignore_default_scope, self)
end
def ignore_default_scope=(ignore) # :nodoc:
- ScopeRegistry.current.set_value_for(:ignore_default_scope, self, ignore)
+ ScopeRegistry.set_value_for(:ignore_default_scope, self, ignore)
end
# The ignore_default_scope flag is used to prevent an infinite recursion