replidog 0.1.0 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2419525361d0fe6b11f5150aa4641aaa33358978
4
- data.tar.gz: 954cdd81a2a5056cf153083d3315e6d5ef39e020
3
+ metadata.gz: 44af9edc1ca7b64ca4c802cec1e865f31318533b
4
+ data.tar.gz: 29a251aad399f14c85813e655dc184b46ecab204
5
5
  SHA512:
6
- metadata.gz: 48aab863f60e64c3efc4aa8f0ca6fe64a3830e0e5b0a3efcfb8a5dd9469aae8b0a8f3c6ff9df1f4767d7afcc43db879488038625d3f51ef25f258f74d97dd1b2
7
- data.tar.gz: ff4b99cd46fe00763a8f82caf7fcbf14ba9c33417bb3993799ddcd669f8fcb827ff61349db335243f68d355c3d5026227eba698f022d0dfb4a867963551ae7ac
6
+ metadata.gz: e8a1858c3e07cbe87e516d80705e448d6afc508a1b5e3c0bc6dc30ebade7cebcb99c8bbe0e03d9465b2b8cdc6247ea08b93d5bcae62633d938530b8808820be0
7
+ data.tar.gz: 09914f2faa17a58fc50f5428efea7b4acc38246da64c57fa3280610c301a20b2e75f255578e5cc665f88dce212157a2c4aba8ff59ccda4a8521c48d3f12a123f
data/Appraisals CHANGED
@@ -1,17 +1,24 @@
1
1
  appraise "rails32" do
2
2
  gem "activerecord", "~> 3.2.0"
3
+ gem "mysql2", '~> 0.3.20'
3
4
  end
4
5
 
5
6
  appraise "rails4" do
6
7
  gem "activerecord", "~> 4.0.0"
8
+ gem "mysql2", '~> 0.3.20'
7
9
  end
8
10
 
9
11
  appraise "rails41" do
10
12
  gem "activerecord", "~> 4.1.0"
13
+ gem "mysql2", '~> 0.3.20'
11
14
  end
12
15
 
13
16
  appraise "rails42" do
14
17
  gem "activerecord", "~> 4.2.0"
15
18
  end
19
+
20
+ appraise "rails5" do
21
+ gem "activerecord", "~> 5.0.0"
22
+ end
16
23
  # vim: ft=ruby
17
24
  #
data/README.md CHANGED
@@ -9,7 +9,7 @@ Based on https://github.com/r7kamura/replicat
9
9
  * Multiple master/slave
10
10
  * Auto switching between master/slave
11
11
  * Supports connection management and query cache
12
- * Supports Rails 3.2, 4.0, 4,1, 4.2
12
+ * Supports Rails 3.2, 4.0, 4,1, 4.2, 5.0
13
13
 
14
14
  ## Installation
15
15
 
@@ -3,5 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "activerecord", "~> 3.2.0"
6
+ gem "mysql2", "~> 0.3.20"
6
7
 
7
8
  gemspec :path => "../"
@@ -3,5 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "activerecord", "~> 4.0.0"
6
+ gem "mysql2", "~> 0.3.20"
6
7
 
7
8
  gemspec :path => "../"
@@ -3,5 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "activerecord", "~> 4.1.0"
6
+ gem "mysql2", "~> 0.3.20"
6
7
 
7
8
  gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 5.0.0"
6
+
7
+ gemspec :path => "../"
@@ -8,28 +8,51 @@ module Replidog
8
8
  base.proxy_handler = Replidog::ProxyHandler.new
9
9
 
10
10
  class << base
11
- alias_method_chain(:establish_connection, :replidog)
12
- alias_method_chain(:connection, :replidog)
13
- alias_method_chain(:connected?, :replidog)
14
- alias_method_chain(:clear_reloadable_connections!, :replidog)
15
- alias_method_chain(:clear_active_connections!, :replidog)
16
- alias_method_chain(:clear_all_connections!, :replidog)
11
+ alias_method :connected_without_replidog?, :connected?
12
+ alias_method :connection_without_replidog, :connection
13
+
14
+ prepend BaseWithReplidogSupport
17
15
  end
18
16
  end
19
17
 
20
- def establish_connection_with_replidog(spec = ENV["DATABASE_URL"])
21
- establish_connection_without_replidog(spec)
22
- proxy_handler.remove_connection(self)
23
- proxy_handler.establish_connection(connection_pool.spec, self)
24
- end
18
+ module BaseWithReplidogSupport
19
+ def establish_connection(spec = ENV["DATABASE_URL"])
20
+ super
21
+ proxy_handler.remove_connection(self)
22
+ proxy_handler.establish_connection(connection_pool.spec, self)
23
+ end
25
24
 
26
- def connection_with_replidog
27
- if replicated?
28
- proxy_handler.retrieve_proxy(self).tap do |proxy|
29
- proxy.current_model = self
25
+ def connection
26
+ if replicated?
27
+ proxy_handler.retrieve_proxy(self).tap do |proxy|
28
+ proxy.current_model = self
29
+ end
30
+ else
31
+ super
30
32
  end
31
- else
32
- connection_without_replidog
33
+ end
34
+
35
+ def connected?
36
+ if replicated?
37
+ connection.connected?
38
+ else
39
+ super
40
+ end
41
+ end
42
+
43
+ def clear_active_connections!
44
+ super
45
+ proxy_handler.clear_active_slave_connections! if replicated?
46
+ end
47
+
48
+ def clear_reloadable_connections!
49
+ super
50
+ proxy_handler.clear_reloadable_slave_connections! if replicated?
51
+ end
52
+
53
+ def clear_all_connections!
54
+ super
55
+ proxy_handler.clear_all_slave_connections! if replicated?
33
56
  end
34
57
  end
35
58
 
@@ -49,29 +72,6 @@ module Replidog
49
72
  end
50
73
  end
51
74
 
52
- def connected_with_replidog?
53
- if replicated?
54
- connection.connected?
55
- else
56
- connected_without_replidog?
57
- end
58
- end
59
-
60
- def clear_active_connections_with_replidog!
61
- clear_active_connections_without_replidog!
62
- proxy_handler.clear_active_slave_connections! if replicated?
63
- end
64
-
65
- def clear_reloadable_connections_with_replidog!
66
- clear_reloadable_connections_without_replidog!
67
- proxy_handler.clear_reloadable_slave_connections! if replicated?
68
- end
69
-
70
- def clear_all_connections_with_replidog!
71
- clear_all_connections_without_replidog!
72
- proxy_handler.clear_all_slave_connections! if replicated?
73
- end
74
-
75
75
  private
76
76
 
77
77
  def _using(connection_name)
@@ -172,12 +172,10 @@ module Replidog
172
172
 
173
173
  def create
174
174
  spec =
175
- if ActiveRecord::VERSION::MAJOR >= 4
176
- if ActiveRecord::VERSION::MINOR < 1
177
- ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new(@configuration, {}).spec
178
- else
179
- ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new({}).spec(@configuration)
180
- end
175
+ if ActiveRecord::VERSION::MAJOR >= 5 || (ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR >= 1)
176
+ ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new({}).spec(@configuration)
177
+ elsif ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR < 1
178
+ ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new(@configuration, {}).spec
181
179
  else
182
180
  ActiveRecord::Base::ConnectionSpecification::Resolver.new(@configuration, {}).spec
183
181
  end
@@ -45,24 +45,34 @@ module Replidog
45
45
  end
46
46
 
47
47
  def enable_query_cache!
48
- ActiveRecord::Base.connection_handler.connection_pools.each_value do |connection_pool|
48
+ connection_pool_list_for(ActiveRecord::Base.connection_handler).each do |connection_pool|
49
49
  connection_pool.connection.enable_query_cache!
50
50
  end
51
51
  @proxies.each_value(&:enable_query_cache_for_slaves!)
52
52
  end
53
53
 
54
54
  def disable_query_cache!
55
- ActiveRecord::Base.connection_handler.connection_pools.each_value do |connection_pool|
55
+ connection_pool_list_for(ActiveRecord::Base.connection_handler).each do |connection_pool|
56
56
  connection_pool.connection.disable_query_cache!
57
57
  end
58
58
  @proxies.each_value(&:disable_query_cache_for_slaves!)
59
59
  end
60
60
 
61
61
  def clear_query_cache
62
- ActiveRecord::Base.connection_handler.connection_pools.each_value do |connection_pool|
62
+ connection_pool_list_for(ActiveRecord::Base.connection_handler).each do |connection_pool|
63
63
  connection_pool.connection.clear_query_cache
64
64
  end
65
65
  @proxies.each_value(&:clear_query_cache_for_slaves)
66
66
  end
67
+
68
+ private
69
+
70
+ def connection_pool_list_for(connection_handler)
71
+ if ActiveRecord::VERSION::MAJOR >= 4
72
+ connection_handler.connection_pool_list
73
+ else
74
+ connection_handler.connection_pools.values
75
+ end
76
+ end
67
77
  end
68
78
  end
@@ -1,3 +1,3 @@
1
1
  module Replidog
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -8,8 +8,8 @@ Dummy::Application.configure do
8
8
  config.cache_classes = true
9
9
 
10
10
  # Configure static asset server for tests with Cache-Control for performance
11
- config.serve_static_assets = true
12
- config.static_cache_control = "public, max-age=3600"
11
+ #config.serve_static_assets = true
12
+ #config.static_cache_control = "public, max-age=3600"
13
13
 
14
14
  # Show full error reports and disable caching
15
15
  config.consider_all_requests_local = true
data/spec/spec_helper.rb CHANGED
@@ -32,7 +32,6 @@ RSpec.configure do |config|
32
32
  end
33
33
 
34
34
  config.run_all_when_everything_filtered = true
35
- config.treat_symbols_as_metadata_keys_with_true_values = true
36
35
  config.filter_run :focus
37
36
 
38
37
  config.before(:suite) do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: replidog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manabu Ejima
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-23 00:00:00.000000000 Z
11
+ date: 2016-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -279,6 +279,7 @@ files:
279
279
  - gemfiles/rails4.gemfile
280
280
  - gemfiles/rails41.gemfile
281
281
  - gemfiles/rails42.gemfile
282
+ - gemfiles/rails5.gemfile
282
283
  - lib/replidog.rb
283
284
  - lib/replidog/active_record.rb
284
285
  - lib/replidog/model.rb