Permalink
Browse files

Integrate request_store to solve threading issues.

Fixes #335.

See also drapergem/draper#390
  • Loading branch information...
1 parent a72ed49 commit fa9625d0df2cf8a9a5b3a2698c98f22a5b6113a7 @steveklabnik committed Dec 17, 2012
Showing with 15 additions and 8 deletions.
  1. +4 −2 Gemfile.lock
  2. +1 −0 authlogic.gemspec
  3. +5 −3 lib/authlogic/session/activation.rb
  4. +5 −3 lib/authlogic/session/scopes.rb
View
@@ -4,6 +4,7 @@ PATH
authlogic (3.2.0)
activerecord (>= 3.0.0)
activesupport (>= 3.0.0)
+ request_store (~> 1.0.1)
GEM
remote: http://rubygems.org/
@@ -23,8 +24,9 @@ GEM
bcrypt-ruby (3.0.1)
builder (3.0.4)
i18n (0.6.1)
- multi_json (1.4.0)
- rake (10.0.2)
+ multi_json (1.5.0)
+ rake (10.0.3)
+ request_store (1.0.1)
scrypt (1.1.0)
sqlite3 (1.3.6)
timecop (0.5.4)
View
@@ -13,6 +13,7 @@ Gem::Specification.new do |s|
s.add_dependency 'activerecord', '>= 3.0.0'
s.add_dependency 'activesupport', '>= 3.0.0'
+ s.add_dependency 'request_store', '~> 1.0.1'
s.add_development_dependency 'rake'
s.add_development_dependency 'bcrypt-ruby'
s.add_development_dependency 'scrypt'
@@ -1,3 +1,5 @@
+require 'request_store'
+
module Authlogic
module Session
# Activating Authlogic requires that you pass it an Authlogic::ControllerAdapters::AbstractAdapter object, or a class that extends it.
@@ -32,12 +34,12 @@ def activated?
#
# Lastly, this is thread safe.
def controller=(value)
- Thread.current[:authlogic_controller] = value
+ RequestStore.store[:authlogic_controller] = value
end
# The current controller object
def controller
- Thread.current[:authlogic_controller]
+ RequestStore.store[:authlogic_controller]
end
end
@@ -55,4 +57,4 @@ def controller
end
end
end
-end
+end
@@ -1,3 +1,5 @@
+require 'request_store'
+
module Authlogic
module Session
# Authentication can be scoped, and it's easy, you just need to define how you want to scope everything. This should help you:
@@ -17,7 +19,7 @@ def self.included(klass)
module ClassMethods
# The current scope set, should be used in the block passed to with_scope.
def scope
- Thread.current[:authlogic_scope]
+ RequestStore.store[:authlogic_scope]
end
# What with_scopes focuses on is scoping the query when finding the object and the name of the cookie / session. It works very similar to
@@ -68,7 +70,7 @@ def with_scope(options = {}, &block)
private
def scope=(value)
- Thread.current[:authlogic_scope] = value
+ RequestStore.store[:authlogic_scope] = value
end
end
@@ -98,4 +100,4 @@ def search_for_record(*args)
end
end
end
-end
+end

0 comments on commit fa9625d

Please sign in to comment.