slave_pools 1.0.0.rc3 → 1.0.0.rc4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/slave_pools/engine.rb +6 -0
- data/lib/slave_pools/version.rb +1 -1
- data/lib/slave_pools.rb +0 -2
- data/spec/config/test_model.rb +1 -18
- data/spec/connection_proxy_spec.rb +3 -2
- data/spec/pool_spec.rb +1 -1
- data/spec/query_cache_spec.rb +3 -0
- data/spec/slave_pools_spec.rb +1 -1
- data/spec/spec_helper.rb +0 -1
- metadata +22 -11
- data/lib/slave_pools/observer_extensions.rb +0 -19
- data/spec/observer_extensions_spec.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d874a3eed928f50de0897109c923c87a142b8530
|
4
|
+
data.tar.gz: 525dd736b487ef2c1c7d025742363ac2e8bbcdf5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6671beaae7b1d6e997b973c15ae8d795c9a8cf5c11b2f2e2c374cd6881270bea3b1211f61ff94e204f99c92ee8f40fc0edc478f9ee36f5aafdd6a1ca2baabf49
|
7
|
+
data.tar.gz: 54ab55daf2d791f86c5f3d707c6bf98c4c6d5d7113b84a7ef75fa4164f6b06e61f267cee8115dfabc78f109c6f9b25d07249bceb0754533dd962c1181680d43b
|
data/lib/slave_pools/engine.rb
CHANGED
@@ -12,6 +12,12 @@ module SlavePools
|
|
12
12
|
:select_rows, :select, :verify!, :raw_connection, :active?, :reconnect!,
|
13
13
|
:disconnect!, :reset_runtime, :log, :log_info
|
14
14
|
]
|
15
|
+
elsif ActiveRecord::VERSION::MAJOR == 4
|
16
|
+
[
|
17
|
+
:select_all, :select_one, :select_value, :select_values,
|
18
|
+
:select_rows, :select, :verify!, :raw_connection, :active?, :reconnect!,
|
19
|
+
:disconnect!, :reset_runtime, :log
|
20
|
+
]
|
15
21
|
else
|
16
22
|
warn "Unsupported ActiveRecord version #{ActiveRecord.version}. Please whitelist the safe methods."
|
17
23
|
end
|
data/lib/slave_pools/version.rb
CHANGED
data/lib/slave_pools.rb
CHANGED
@@ -4,12 +4,10 @@ require 'slave_pools/pool'
|
|
4
4
|
require 'slave_pools/pools'
|
5
5
|
require 'slave_pools/active_record_extensions'
|
6
6
|
require 'slave_pools/hijack'
|
7
|
-
require 'slave_pools/observer_extensions'
|
8
7
|
require 'slave_pools/query_cache'
|
9
8
|
require 'slave_pools/connection_proxy'
|
10
9
|
|
11
10
|
require 'slave_pools/engine' if defined? Rails
|
12
|
-
ActiveRecord::Observer.send :include, SlavePools::ObserverExtensions
|
13
11
|
ActiveRecord::Base.send :include, SlavePools::ActiveRecordExtensions
|
14
12
|
|
15
13
|
module SlavePools
|
data/spec/config/test_model.rb
CHANGED
@@ -1,19 +1,2 @@
|
|
1
1
|
class TestModel < ActiveRecord::Base
|
2
|
-
|
3
|
-
end
|
4
|
-
|
5
|
-
class TestSub < ActiveRecord::Base
|
6
|
-
belongs_to :test_model
|
7
|
-
end
|
8
|
-
|
9
|
-
class TestModelObserver < ActiveRecord::Observer
|
10
|
-
|
11
|
-
def after_create(test_model)
|
12
|
-
ActiveRecord::Base.logger.info "in observer"
|
13
|
-
TestSub.create(:test_model=>test_model)
|
14
|
-
TestModel.first
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
|
19
|
-
|
2
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
require_relative 'config/test_model'
|
2
3
|
|
3
4
|
describe SlavePools do
|
4
5
|
|
@@ -165,7 +166,7 @@ describe SlavePools do
|
|
165
166
|
|
166
167
|
it 'should reload models from the master' do
|
167
168
|
foo = TestModel.create!
|
168
|
-
@master.should_receive(:select_all).and_return([
|
169
|
+
@master.should_receive(:select_all).and_return(ActiveRecord::Result.new(["id"], ["1"]))
|
169
170
|
@default_slave1.should_not_receive(:select_all)
|
170
171
|
@default_slave2.should_not_receive(:select_all)
|
171
172
|
foo.reload
|
data/spec/pool_spec.rb
CHANGED
data/spec/query_cache_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'rack'
|
1
2
|
require_relative 'spec_helper'
|
2
3
|
|
3
4
|
describe SlavePools::QueryCache do
|
@@ -55,6 +56,7 @@ describe SlavePools::QueryCache do
|
|
55
56
|
@proxy.next_slave!
|
56
57
|
3.times { @proxy.select_all(@sql)}
|
57
58
|
@master.query_cache.keys.size.should == 1
|
59
|
+
[200, {}, nil]
|
58
60
|
}
|
59
61
|
mw.call({})
|
60
62
|
end
|
@@ -75,6 +77,7 @@ describe SlavePools::QueryCache do
|
|
75
77
|
@proxy.send(meths[i], '')
|
76
78
|
@master.query_cache.keys.size.should == 0
|
77
79
|
end
|
80
|
+
[200, {}, nil]
|
78
81
|
}
|
79
82
|
mw.call({})
|
80
83
|
end
|
data/spec/slave_pools_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -16,7 +16,6 @@ ActiveRecord::Base.configurations = YAML::load(File.open(spec_dir + '/config/dat
|
|
16
16
|
ActiveRecord::Base.establish_connection :test
|
17
17
|
ActiveRecord::Migration.verbose = false
|
18
18
|
ActiveRecord::Migration.create_table(:test_models, :force => true) {}
|
19
|
-
ActiveRecord::Migration.create_table(:test_subs, :force => true) {|t| t.integer :test_model_id}
|
20
19
|
|
21
20
|
require 'slave_pools'
|
22
21
|
SlavePools::Engine.initializers.each(&:run)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slave_pools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.rc4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Drabik
|
@@ -9,20 +9,20 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-03-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - '>='
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: 3.2.12
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - '>='
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: 3.2.12
|
28
28
|
- !ruby/object:Gem::Dependency
|
@@ -39,6 +39,20 @@ dependencies:
|
|
39
39
|
- - ~>
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: 0.3.11
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rack
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
42
56
|
- !ruby/object:Gem::Dependency
|
43
57
|
name: rspec
|
44
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,22 +101,20 @@ executables: []
|
|
87
101
|
extensions: []
|
88
102
|
extra_rdoc_files: []
|
89
103
|
files:
|
90
|
-
- LICENSE
|
91
|
-
- README.md
|
92
|
-
- lib/slave_pools.rb
|
93
104
|
- lib/slave_pools/active_record_extensions.rb
|
94
105
|
- lib/slave_pools/config.rb
|
95
106
|
- lib/slave_pools/connection_proxy.rb
|
96
107
|
- lib/slave_pools/engine.rb
|
97
108
|
- lib/slave_pools/hijack.rb
|
98
|
-
- lib/slave_pools/observer_extensions.rb
|
99
109
|
- lib/slave_pools/pool.rb
|
100
110
|
- lib/slave_pools/pools.rb
|
101
111
|
- lib/slave_pools/query_cache.rb
|
102
112
|
- lib/slave_pools/version.rb
|
113
|
+
- lib/slave_pools.rb
|
114
|
+
- LICENSE
|
115
|
+
- README.md
|
103
116
|
- spec/config/test_model.rb
|
104
117
|
- spec/connection_proxy_spec.rb
|
105
|
-
- spec/observer_extensions_spec.rb
|
106
118
|
- spec/pool_spec.rb
|
107
119
|
- spec/query_cache_spec.rb
|
108
120
|
- spec/slave_pools_spec.rb
|
@@ -127,14 +139,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
139
|
version: '1.2'
|
128
140
|
requirements: []
|
129
141
|
rubyforge_project:
|
130
|
-
rubygems_version: 2.
|
142
|
+
rubygems_version: 2.0.3
|
131
143
|
signing_key:
|
132
144
|
specification_version: 4
|
133
145
|
summary: Connection proxy for ActiveRecord for master / replica setups.
|
134
146
|
test_files:
|
135
147
|
- spec/config/test_model.rb
|
136
148
|
- spec/connection_proxy_spec.rb
|
137
|
-
- spec/observer_extensions_spec.rb
|
138
149
|
- spec/pool_spec.rb
|
139
150
|
- spec/query_cache_spec.rb
|
140
151
|
- spec/slave_pools_spec.rb
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module SlavePools
|
2
|
-
module ObserverExtensions
|
3
|
-
def self.included(base)
|
4
|
-
base.alias_method_chain :update, :masterdb
|
5
|
-
end
|
6
|
-
|
7
|
-
# Send observed_method(object) if the method exists.
|
8
|
-
# currently replicating the update method instead of using the aliased method call to update_without_master
|
9
|
-
def update_with_masterdb(observed_method, object, &block) #:nodoc:
|
10
|
-
if object.class.connection.respond_to?(:with_master)
|
11
|
-
object.class.connection.with_master do
|
12
|
-
update_without_masterdb(observed_method, object)
|
13
|
-
end
|
14
|
-
else
|
15
|
-
update_without_masterdb(observed_method, object)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + '/config/test_model')
|
3
|
-
|
4
|
-
describe SlavePools do
|
5
|
-
|
6
|
-
before(:each) do
|
7
|
-
reset_proxy(SlavePools.proxy)
|
8
|
-
@observer = TestModelObserver.instance
|
9
|
-
|
10
|
-
@test_model = TestModel.create
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should use observers correctly" do
|
14
|
-
TestSub.first.test_model_id.should == @test_model.id
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should not throw a stack too deep error" do
|
18
|
-
@test_model.should be_valid
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|