master_slave 3.0.0 → 3.2.0
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.
@@ -25,20 +25,27 @@ module MasterSlave
|
|
25
25
|
def setup_connection
|
26
26
|
ActiveRecord::Base.slave_connection_names ||= []
|
27
27
|
MasterSlave.config.slave_names.each do |slave_name|
|
28
|
+
# activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb +128
|
28
29
|
ActiveRecord::Base.slave_connection_names << slave_name.to_s.strip
|
29
30
|
configuration = MasterSlave.config.slave_config(slave_name).symbolize_keys
|
30
|
-
unless configuration.key?(:adapter) then raise AdapterNotSpecified, "database configuration does not specify adapter" end
|
31
31
|
|
32
|
-
|
33
|
-
|
32
|
+
resolver = ActiveRecord::Base::ConnectionSpecification::Resolver.new(configuration, nil)
|
33
|
+
|
34
|
+
spec = resolver.spec
|
35
|
+
|
36
|
+
unless ActiveRecord::Base.respond_to?(spec.adapter_method)
|
34
37
|
raise AdapterNotFound, "database configuration specifies nonexistent #{spec.config[:adapter]} adapter"
|
35
38
|
end
|
36
39
|
|
37
|
-
# remove_connection 时会调用方法内部 ar_proxy.name
|
38
40
|
ar_proxy = ArProxy.new(connection_pool_name(slave_name))
|
41
|
+
|
42
|
+
# activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb +179
|
43
|
+
# activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +424
|
44
|
+
# remove_connection 时会调用方法内部 ar_proxy.name
|
39
45
|
ActiveRecord::Base.remove_connection(ar_proxy)
|
40
46
|
|
41
|
-
|
47
|
+
# activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +373
|
48
|
+
# establish_connection 时,使用 ar_proxy.name
|
42
49
|
ActiveRecord::Base.connection_handler.establish_connection ar_proxy.name, spec
|
43
50
|
end
|
44
51
|
end
|
data/lib/master_slave/railtie.rb
CHANGED
@@ -3,13 +3,13 @@ module MasterSlave
|
|
3
3
|
|
4
4
|
config.after_initialize do
|
5
5
|
if File.exist?(MasterSlave::Configuration.config_file)
|
6
|
-
|
6
|
+
Rails.logger.info "\033[32mmaster_slave is on!\033[0m"
|
7
7
|
ActiveRecord::Base.send :include, MasterSlave::Base
|
8
8
|
MasterSlave::ConnectionHandler.setup
|
9
9
|
else
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
Rails.logger.error "\033[31mNo such file #{MasterSlave::Configuration.config_file}\033[0m"
|
11
|
+
Rails.logger.error "\033[31mPlease execute `rails g master_slave:config`\033[0m"
|
12
|
+
Rails.logger.error "\033[31mmaster_slave is off!\033[0m"
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
data/lib/master_slave/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: master_slave
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -16,10 +16,7 @@ dependencies:
|
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: 3.0.0
|
22
|
-
- - <
|
19
|
+
- - ~>
|
23
20
|
- !ruby/object:Gem::Version
|
24
21
|
version: 3.2.0
|
25
22
|
type: :runtime
|
@@ -27,10 +24,7 @@ dependencies:
|
|
27
24
|
version_requirements: !ruby/object:Gem::Requirement
|
28
25
|
none: false
|
29
26
|
requirements:
|
30
|
-
- -
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 3.0.0
|
33
|
-
- - <
|
27
|
+
- - ~>
|
34
28
|
- !ruby/object:Gem::Version
|
35
29
|
version: 3.2.0
|
36
30
|
description: mysql separate read and write.
|