Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/schoefmax/multi_db
Browse files Browse the repository at this point in the history
  • Loading branch information
guimello committed Apr 9, 2012
2 parents d42f1a4 + 5bf963b commit 8aa5f5e
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,3 +1,5 @@
spec/debug.log spec/debug.log
experimental experimental
.rvmrc
Gemfile.lock


12 changes: 7 additions & 5 deletions README.rdoc
Expand Up @@ -28,13 +28,15 @@ master database.
* works with activerecord 2.1, 2.2, 2.3, and 3.0 * works with activerecord 2.1, 2.2, 2.3, and 3.0


=== Install === Install
==== Rails 2
gem install multi_db


gem sources --add http://gems.github.com # only if you haven't already added github Then add this to your environment.rb:
gem install schoefmax-multi_db config.gem 'multi_db', :lib => 'multi_db'


When using Rails, add this to your environment.rb: ==== Rails 3

put this in your Gemfile
config.gem 'schoefmax-multi_db', :lib => 'multi_db', :source => 'http://gems.github.com' gem 'multi_db'


=== Setup === Setup


Expand Down
2 changes: 1 addition & 1 deletion lib/multi_db/active_record_extensions.rb
Expand Up @@ -18,7 +18,7 @@ def reload(options = nil)


module ClassMethods module ClassMethods
# Make sure transactions always switch to the master # Make sure transactions always switch to the master
def transaction(&block) def transaction(options = {}, &block)
if self.connection.kind_of?(ConnectionProxy) if self.connection.kind_of?(ConnectionProxy)
super super
else else
Expand Down
4 changes: 2 additions & 2 deletions lib/multi_db/connection_proxy.rb
Expand Up @@ -28,7 +28,7 @@ class ConnectionProxy


class << self 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 # defaults to 'development' when used outside Rails
attr_accessor :environment attr_accessor :environment


Expand All @@ -52,7 +52,7 @@ class << self
# establishes the connections to the slaves. # establishes the connections to the slaves.
def setup!(scheduler = Scheduler) def setup!(scheduler = Scheduler)
self.master_models ||= DEFAULT_MASTER_MODELS 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 self.sticky_slave ||= false


master = ActiveRecord::Base master = ActiveRecord::Base
Expand Down
2 changes: 1 addition & 1 deletion lib/multi_db/scheduler.rb
Expand Up @@ -12,7 +12,7 @@ def initialize(items, blacklist_timeout = 1.minute)
@items = items @items = items
@blacklist = Array.new(@n, Time.at(0)) @blacklist = Array.new(@n, Time.at(0))
@blacklist_timeout = blacklist_timeout @blacklist_timeout = blacklist_timeout
self.current_index = 0 self.current_index = rand(@n)
end end


def blacklist!(item) def blacklist!(item)
Expand Down
5 changes: 3 additions & 2 deletions multi_db.gemspec
@@ -1,12 +1,13 @@
# coding: utf-8
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-


Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = %q{multi_db} 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.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.authors = ["Maximilian Sch\303\266fmann"] 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.description = "Connection proxy for ActiveRecord for single master / multiple slave database deployments"
s.email = "max@pragmatic-it.de" s.email = "max@pragmatic-it.de"
s.extra_rdoc_files = ["LICENSE", "README.rdoc"] s.extra_rdoc_files = ["LICENSE", "README.rdoc"]
Expand Down
2 changes: 0 additions & 2 deletions spec/connection_proxy_spec.rb
Expand Up @@ -5,8 +5,6 @@
require MULTI_DB_SPEC_DIR + '/../lib/multi_db/scheduler' require MULTI_DB_SPEC_DIR + '/../lib/multi_db/scheduler'
require MULTI_DB_SPEC_DIR + '/../lib/multi_db/connection_proxy' require MULTI_DB_SPEC_DIR + '/../lib/multi_db/connection_proxy'


RAILS_ROOT = MULTI_DB_SPEC_DIR

describe MultiDb::ConnectionProxy do describe MultiDb::ConnectionProxy do


before(:all) do before(:all) do
Expand Down
8 changes: 6 additions & 2 deletions spec/spec_helper.rb
Expand Up @@ -2,10 +2,14 @@
gem 'activerecord', '3.0.5' gem 'activerecord', '3.0.5'
%w[tlattr_accessors active_record yaml erb rspec logger].each {|lib| require lib} %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_DIR = File.dirname(__FILE__)
MULTI_DB_SPEC_CONFIG = YAML::load(File.open(MULTI_DB_SPEC_DIR + '/config/database.yml')) 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.logger = Logger.new(MULTI_DB_SPEC_DIR + "/debug.log")
ActiveRecord::Base.configurations = MULTI_DB_SPEC_CONFIG ActiveRecord::Base.configurations = MULTI_DB_SPEC_CONFIG
3 changes: 1 addition & 2 deletions spec/weighted_scheduler_spec.rb
Expand Up @@ -6,7 +6,6 @@
require MULTI_DB_SPEC_DIR + '/../lib/multi_db/scheduler' require MULTI_DB_SPEC_DIR + '/../lib/multi_db/scheduler'
require MULTI_DB_SPEC_DIR + '/../lib/multi_db/weighted_scheduler' require MULTI_DB_SPEC_DIR + '/../lib/multi_db/weighted_scheduler'


RAILS_ROOT = MULTI_DB_SPEC_DIR
describe MultiDb::WeightedScheduler do describe MultiDb::WeightedScheduler do


before(:each) do before(:each) do
Expand Down Expand Up @@ -64,4 +63,4 @@ class FooModel < ActiveRecord::Base; end
end end
end end
end end
end end

0 comments on commit 8aa5f5e

Please sign in to comment.