Permalink
Browse files

IM enable should be kept in current thread.

  • Loading branch information...
1 parent a12bb71 commit d9c0340ac3da67ae880d3a53c8bca8169daf0f29 @miloops miloops committed Nov 18, 2010
Showing with 10 additions and 7 deletions.
  1. +10 −7 activerecord/lib/active_record/identity_map.rb
@@ -18,14 +18,21 @@ module IdentityMap
extend ActiveSupport::Concern
class << self
- attr_accessor :enabled
+ def enabled=(flag)
+ Thread.current[:identity_map_enabled] = flag
+ end
+
+ def enabled
+ Thread.current[:identity_map_enabled]
+ end
+ alias enabled? enabled
def repository
Thread.current[:identity_map] ||= Hash.new { |h,k| h[k] = {} }
end
def use
- old, self.enabled = self.enabled, true
+ old, self.enabled = enabled, true
yield if block_given?
ensure
@@ -34,7 +41,7 @@ def use
end
def without
- old, self.enabled = self.enabled, false
+ old, self.enabled = enabled, false
yield if block_given?
ensure
@@ -61,12 +68,8 @@ def remove_by_id(symbolized_base_class, id)
def clear
repository.clear
end
-
- alias enabled? enabled
end
- self.enabled = false
-
module InstanceMethods
# Reinitialize an Identity Map model object from +coder+.
# +coder+ must contain the attributes necessary for initializing an empty

0 comments on commit d9c0340

Please sign in to comment.