switch_point 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/switch_point/config.rb +1 -1
- data/lib/switch_point/proxy.rb +8 -0
- data/lib/switch_point/version.rb +1 -1
- data/spec/models.rb +8 -0
- data/spec/switch_point/model_spec.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7214878a8ac1b215808ee7fb386f02643ca94961
|
4
|
+
data.tar.gz: 05cad4a43106ab868ed8bcc47be9ed881a202f7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6344f088708f67f8bb5bf8d55ed908356469cffda84c7ae65e96e82fa72394f002c26857e576410ee6c3c72b9bfc5e5700e72d07a01e6eab6191a87cd60d1e98
|
7
|
+
data.tar.gz: 0cebcc98ac866bddc15bd8bc5b1a85669cf09aaadbadeaca24c0fa0b531a4d9e65986ac4dca65f40e90911f319c7e704b51ffc17ba5a28c4755ab2dac248482c
|
data/CHANGELOG.md
CHANGED
data/lib/switch_point/config.rb
CHANGED
data/lib/switch_point/proxy.rb
CHANGED
@@ -28,10 +28,18 @@ module SwitchPoint
|
|
28
28
|
@mode = :readonly
|
29
29
|
end
|
30
30
|
|
31
|
+
def readonly?
|
32
|
+
@mode == :readonly
|
33
|
+
end
|
34
|
+
|
31
35
|
def writable!
|
32
36
|
@mode = :writable
|
33
37
|
end
|
34
38
|
|
39
|
+
def writable?
|
40
|
+
@mode == :writable
|
41
|
+
end
|
42
|
+
|
35
43
|
def with_readonly(&block)
|
36
44
|
with_connection(:readonly, &block)
|
37
45
|
end
|
data/lib/switch_point/version.rb
CHANGED
data/spec/models.rb
CHANGED
@@ -8,6 +8,9 @@ SwitchPoint.configure do |config|
|
|
8
8
|
config.define_switch_point :comment,
|
9
9
|
readonly: :comment_readonly,
|
10
10
|
writable: :comment_writable
|
11
|
+
config.define_switch_point :special,
|
12
|
+
readonly: :main_readonly_special,
|
13
|
+
writable: :main_writable
|
11
14
|
end
|
12
15
|
|
13
16
|
class Book < ActiveRecord::Base
|
@@ -26,6 +29,10 @@ class User < ActiveRecord::Base
|
|
26
29
|
use_switch_point :user
|
27
30
|
end
|
28
31
|
|
32
|
+
class BigData < ActiveRecord::Base
|
33
|
+
use_switch_point :special
|
34
|
+
end
|
35
|
+
|
29
36
|
class Note < ActiveRecord::Base
|
30
37
|
end
|
31
38
|
|
@@ -33,6 +40,7 @@ base = { adapter: 'sqlite3' }
|
|
33
40
|
ActiveRecord::Base.configurations = {
|
34
41
|
'main_readonly' => base.merge(database: 'main_readonly.sqlite3'),
|
35
42
|
'main_writable' => base.merge(database: 'main_writable.sqlite3'),
|
43
|
+
'main_readonly_special' => base.merge(database: 'main_readonly_special.sqlite3'),
|
36
44
|
'user' => base.merge(database: 'user.sqlite3'),
|
37
45
|
'comment_readonly' => base.merge(database: 'comment_readonly.sqlite3'),
|
38
46
|
'comment_writable' => base.merge(database: 'comment_writable.sqlite3'),
|
@@ -28,6 +28,7 @@ RSpec.describe SwitchPoint::Model do
|
|
28
28
|
expect(User).to connect_to('user.sqlite3')
|
29
29
|
expect(Comment).to connect_to('comment_readonly.sqlite3')
|
30
30
|
expect(Note).to connect_to('default.sqlite3')
|
31
|
+
expect(Book.switch_point_proxy).to be_readonly
|
31
32
|
end
|
32
33
|
|
33
34
|
it 'sends destructive queries to writable' do
|
@@ -56,14 +57,27 @@ RSpec.describe SwitchPoint::Model do
|
|
56
57
|
expect(Book.connection).to equal(Publisher.connection)
|
57
58
|
end
|
58
59
|
end
|
60
|
+
|
61
|
+
context 'with the same database name' do
|
62
|
+
it 'does NOT shares a connection' do
|
63
|
+
expect(Book.connection).to_not equal(BigData.connection)
|
64
|
+
Book.with_writable do
|
65
|
+
BigData.with_writable do
|
66
|
+
expect(Book.connection).to_not equal(BigData.connection)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
59
71
|
end
|
60
72
|
|
61
73
|
describe '.with_writable' do
|
62
74
|
it 'changes connection locally' do
|
63
75
|
Book.with_writable do
|
64
76
|
expect(Book).to connect_to('main_writable.sqlite3')
|
77
|
+
expect(Book.switch_point_proxy).to be_writable
|
65
78
|
end
|
66
79
|
expect(Book).to connect_to('main_readonly.sqlite3')
|
80
|
+
expect(Book.switch_point_proxy).to be_readonly
|
67
81
|
end
|
68
82
|
|
69
83
|
it 'affects to other models with the same switch point' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: switch_point
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kohei Suzuki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: appraisal
|