From bfedf743a3e1bbefd0153ab327aaf0b06ffbb237 Mon Sep 17 00:00:00 2001 From: tra Date: Mon, 9 Mar 2009 20:22:20 +0000 Subject: [PATCH] use global namespace when checking rails version to avoid conflicts in gettext git-svn-id: svn+ssh://rubyforge.org/var/svn/spawn/spawn@31 2aabfe31-cc40-457c-aec7-21ad9ce7fb7d --- README | 1 + lib/patches.rb | 4 ++-- lib/spawn.rb | 6 ++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README b/README index a9bd1bf..59b0690 100644 --- a/README +++ b/README @@ -112,6 +112,7 @@ blog post on threading in rails. Also thanks to all who have helped debug problems and suggest improvements including: Ahmed Adam, Tristan Schneiter, Scott Haug, Andrew Garfield, Eugene Otto, Dan Sharp, + Olivier Ruffin Garry Tan, Matt Jankowski (2.2.x fixes) Tim Kadom, Mauricio Marcon Zaffari (passenger fixes) diff --git a/lib/patches.rb b/lib/patches.rb index 06ea098..f4447bc 100644 --- a/lib/patches.rb +++ b/lib/patches.rb @@ -1,7 +1,7 @@ # see activerecord/lib/active_record/connection_adaptors/abstract/connection_specification.rb class ActiveRecord::Base # reconnect without disconnecting - if Rails::VERSION::MAJOR == 2 && Rails::VERSION::MINOR >= 2 + if Spawn::RAILS_2_2 def self.spawn_reconnect(klass=self) @@connection_handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new establish_connection @@ -19,7 +19,7 @@ def self.spawn_reconnect(klass=self) end # this patch not needed on Rails 2.x and later - if ::Rails::VERSION::MAJOR == 1 + if Spawn::RAILS_1_x # monkey patch to fix threading problems, # see: http://dev.rubyonrails.org/ticket/7579 def self.clear_reloadable_connections! diff --git a/lib/spawn.rb b/lib/spawn.rb index fe3d404..157d826 100644 --- a/lib/spawn.rb +++ b/lib/spawn.rb @@ -1,4 +1,6 @@ module Spawn + RAILS_1_x = (::Rails::VERSION::MAJOR == 1) + RAILS_2_2 = (::Rails::VERSION::MAJOR > 2 || (::Rails::VERSION::MAJOR == 2 && ::Rails::VERSION::MINOR >= 2)) # default to forking (unless windows or jruby) @@method = (RUBY_PLATFORM =~ /(win32|java)/) ? :thread : :fork @@ -42,7 +44,7 @@ def spawn(options = {}) yield elsif options[:method] == :thread || (options[:method] == nil && @@method == :thread) # for versions before 2.2, check for allow_concurrency - if Rails::VERSION::MAJOR > 2 || (Rails::VERSION::MAJOR == 2 && Rails::VERSION::MINOR >= 2) || ActiveRecord::Base.allow_concurrency + if RAILS_2_2 || ActiveRecord::Base.allow_concurrency thread_it(options) { yield } else @@logger.error("spawn(:method=>:thread) only allowed when allow_concurrency=true") @@ -105,7 +107,7 @@ def fork_it(options) ensure begin # to be safe, catch errors on closing the connnections too - if Rails::VERSION::MAJOR >= 2 && Rails::VERSION::MINOR >= 2 + if RAILS_2_2 ActiveRecord::Base.connection_handler.clear_all_connections! else ActiveRecord::Base.connection.disconnect!