Skip to content
Browse files

Use RequestStore instead of Thread.current to fix #24. Clean up depen…

…dency requirements.
  • Loading branch information...
1 parent ffa49df commit 5325b47b392adfcbe9068e3c63ba88a1d099cf82 @ErwinM committed
Showing with 8 additions and 15 deletions.
  1. +3 −0 acts_as_tenant.gemspec
  2. +1 −1 lib/acts_as_tenant.rb
  3. +2 −2 lib/acts_as_tenant/model_extensions.rb
  4. +2 −12 spec/spec_helper.rb
View
3 acts_as_tenant.gemspec
@@ -18,7 +18,10 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
+ #add_runtime_dependency("rails")
+ s.add_runtime_dependency('request_store', '>= 1.0.5')
s.add_dependency('rails','>= 3.1')
+ #s.add_dependency('request_store', '>= 1.0.5')
s.add_development_dependency('rspec')
s.add_development_dependency('database_cleaner')
View
2 lib/acts_as_tenant.rb
@@ -3,10 +3,10 @@
require "active_record"
require "action_controller"
require "active_model"
+require "request_store"
#$LOAD_PATH.unshift(File.dirname(__FILE__))
-require "acts_as_tenant"
require "acts_as_tenant/version"
require "acts_as_tenant/errors"
require "acts_as_tenant/configuration"
View
4 lib/acts_as_tenant/model_extensions.rb
@@ -14,11 +14,11 @@ def self.fkey
end
def self.current_tenant=(tenant)
- Thread.current[:current_tenant] = tenant
+ RequestStore.store[:current_tenant] = tenant
end
def self.current_tenant
- Thread.current[:current_tenant]
+ RequestStore.store[:current_tenant]
end
def self.with_tenant(tenant, &block)
View
14 spec/spec_helper.rb
@@ -1,18 +1,8 @@
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
-require 'rspec'
-require 'active_record'
-require 'action_controller'
-require 'logger'
-require 'database_cleaner'
-
-require 'acts_as_tenant/errors'
-require 'acts_as_tenant/configuration'
-require 'acts_as_tenant/model_extensions'
-require 'acts_as_tenant/controller_extensions'
-ActiveRecord::Base.send(:include, ActsAsTenant::ModelExtensions)
-ActionController::Base.extend ActsAsTenant::ControllerExtensions
+require 'database_cleaner'
+require 'acts_as_tenant'
config = YAML::load(IO.read(File.join(File.dirname(__FILE__), 'database.yml')))
ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))

0 comments on commit 5325b47

Please sign in to comment.
Something went wrong with that request. Please try again.