Permalink
Browse files

Merge branch 'master' of https://github.com/schoefmax/multi_db

  • Loading branch information...
guimello committed Apr 9, 2012
2 parents d42f1a4 + 5bf963b commit 8aa5f5e9ef9752de4fd89b9b88b5ead3a4a9911f
View
@@ -1,3 +1,5 @@
spec/debug.log
experimental
+.rvmrc
+Gemfile.lock
View
@@ -28,13 +28,15 @@ master database.
* works with activerecord 2.1, 2.2, 2.3, and 3.0
=== Install
+==== Rails 2
+ gem install multi_db
- gem sources --add http://gems.github.com # only if you haven't already added github
- gem install schoefmax-multi_db
+Then add this to your environment.rb:
+ config.gem 'multi_db', :lib => 'multi_db'
-When using Rails, add this to your environment.rb:
-
- config.gem 'schoefmax-multi_db', :lib => 'multi_db', :source => 'http://gems.github.com'
+==== Rails 3
+put this in your Gemfile
+ gem 'multi_db'
=== Setup
@@ -18,7 +18,7 @@ def reload(options = nil)
module ClassMethods
# Make sure transactions always switch to the master
- def transaction(&block)
+ def transaction(options = {}, &block)
if self.connection.kind_of?(ConnectionProxy)
super
else
@@ -28,7 +28,7 @@ class ConnectionProxy
class << self
- # defaults to RAILS_ENV if multi_db is used with Rails
+ # defaults to Rails.env if multi_db is used with Rails
# defaults to 'development' when used outside Rails
attr_accessor :environment
@@ -52,7 +52,7 @@ class << self
# establishes the connections to the slaves.
def setup!(scheduler = Scheduler)
self.master_models ||= DEFAULT_MASTER_MODELS
- self.environment ||= (defined?(RAILS_ENV) ? RAILS_ENV : 'development')
+ self.environment ||= (defined?(Rails) ? Rails.env : 'development')
self.sticky_slave ||= false
master = ActiveRecord::Base
@@ -12,7 +12,7 @@ def initialize(items, blacklist_timeout = 1.minute)
@items = items
@blacklist = Array.new(@n, Time.at(0))
@blacklist_timeout = blacklist_timeout
- self.current_index = 0
+ self.current_index = rand(@n)
end
def blacklist!(item)
View
@@ -1,12 +1,13 @@
+# coding: utf-8
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = %q{multi_db}
- s.version = "0.3.0"
+ s.version = "0.3.1"
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.authors = ["Maximilian Sch\303\266fmann"]
- s.date = %q{2011-05-17}
+ s.date = %q{2012-03-29}
s.description = "Connection proxy for ActiveRecord for single master / multiple slave database deployments"
s.email = "max@pragmatic-it.de"
s.extra_rdoc_files = ["LICENSE", "README.rdoc"]
@@ -5,8 +5,6 @@
require MULTI_DB_SPEC_DIR + '/../lib/multi_db/scheduler'
require MULTI_DB_SPEC_DIR + '/../lib/multi_db/connection_proxy'
-RAILS_ROOT = MULTI_DB_SPEC_DIR
-
describe MultiDb::ConnectionProxy do
before(:all) do
View
@@ -2,10 +2,14 @@
gem 'activerecord', '3.0.5'
%w[tlattr_accessors active_record yaml erb rspec logger].each {|lib| require lib}
-RAILS_ENV = ENV['RAILS_ENV'] = 'test'
+module Rails
+ def self.env
+ ActiveSupport::StringInquirer.new("test")
+ end
+end
MULTI_DB_SPEC_DIR = File.dirname(__FILE__)
MULTI_DB_SPEC_CONFIG = YAML::load(File.open(MULTI_DB_SPEC_DIR + '/config/database.yml'))
ActiveRecord::Base.logger = Logger.new(MULTI_DB_SPEC_DIR + "/debug.log")
-ActiveRecord::Base.configurations = MULTI_DB_SPEC_CONFIG
+ActiveRecord::Base.configurations = MULTI_DB_SPEC_CONFIG
@@ -6,7 +6,6 @@
require MULTI_DB_SPEC_DIR + '/../lib/multi_db/scheduler'
require MULTI_DB_SPEC_DIR + '/../lib/multi_db/weighted_scheduler'
-RAILS_ROOT = MULTI_DB_SPEC_DIR
describe MultiDb::WeightedScheduler do
before(:each) do
@@ -64,4 +63,4 @@ class FooModel < ActiveRecord::Base; end
end
end
end
-end
+end

0 comments on commit 8aa5f5e

Please sign in to comment.