activerecord_autoreplica 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4842ab6d5f5cbf12c929f25b2933aca4eb6c034e
4
- data.tar.gz: 94caf1b3480ea4ca6170571dc2d264e1d85f1e2d
3
+ metadata.gz: 8ed3fdce7e191b78e8bc24c13cc926cb9b625052
4
+ data.tar.gz: 02bdd2ae70931f1a7376a9264bf6a5ac6442275e
5
5
  SHA512:
6
- metadata.gz: e199dcaaa96886e1aeb7d10f022b840280abea1fd00f0ce4d114c6db332e12a81c19e71e43cf1af5cd7327c81df44d626f7fe4e99925653a0e51f98f98e89375
7
- data.tar.gz: 475170a5a2e715a729d9da07c5a022866234df582e1caaa0930c318ea9b2c7b31e3ceb722d352b9eaec4735acdfe7eeb561175ad7c7e6b5579f18ce88cdca61b
6
+ metadata.gz: fa680e51be925cbe09927aa323e44be88fd26cf82b799474761bbae59a135a2123e1f459e9e350f9949eb58462338e7dc433558aaa9156463d8881fe141f82cf
7
+ data.tar.gz: 7db0c18d68ed48fdbf428d56bff0f49a1ec5137ef8f5c10e695eef9d41ec3e860a52ffff11256eb2525f98c7b004ecf1b4e465d8fa711e1d1dde932252250f5f
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ gemfile:
2
+ - gemfiles/Gemfile.rails-3.2.x
3
+ - gemfiles/Gemfile.rails-4.1.x
4
+ - gemfiles/Gemfile.rails-5.0.x
5
+ rvm:
6
+ - 2.0.0
7
+ - 2.1.1
8
+ - 2.2.5
9
+ - 2.3.0
10
+ matrix:
11
+ exclude:
12
+ - rvm: 2.0.0
13
+ gemfile: gemfiles/Gemfile.rails-5.0.x
14
+ - rvm: 2.1.1
15
+ gemfile: gemfiles/Gemfile.rails-5.0.x
16
+ cache: bundler
17
+ sudo: false
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown
data/Gemfile CHANGED
@@ -11,6 +11,8 @@ gem 'activerecord', "> 3.0"
11
11
  # Add dependencies to develop your gem here.
12
12
  # Include everything needed to run rake, tests, features, etc.
13
13
  group :development do
14
+ gem 'rake', '~> 10.0'
15
+ gem 'yard'
14
16
  gem 'sqlite3'
15
17
  gem "rspec", "~> 2.4"
16
18
  gem "rdoc", "~> 3.12"
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # activerecord_autoreplica
2
2
 
3
+ [![Build Status](https://travis-ci.org/WeTransfer/activerecord_autoreplica.svg)](https://travis-ci.org/WeTransfer/activerecord_autoreplica)
4
+
3
5
  An automatic ActiveRecord connection multiplexer, and is a reimplementation of / greatly inspired by
4
6
  the [makara gem](https://github.com/taskrabbit/makara)
5
7
 
@@ -64,10 +66,12 @@ files are going to be erased on test completion.
64
66
 
65
67
  There are Gemfiles for testing against various versions of ActiveRecord. To run those, use:
66
68
 
69
+ $ BUNDLE_GEMFILE=gemfiles/Gemfile.rails-5.0.x bundle exec rake
67
70
  $ BUNDLE_GEMFILE=gemfiles/Gemfile.rails-4.1.x bundle exec rake
68
71
  $ BUNDLE_GEMFILE=gemfiles/Gemfile.rails-3.2.x bundle exec rake
69
72
 
70
- The library contains a couple of switches that allow it to function in both Rails versions.
73
+ The library contains a couple of switches that allow it to function in all these Rails versions.
74
+ Rails 3.x support is likely to be dropped in the next major version.
71
75
 
72
76
  ### Versioning
73
77
 
@@ -85,6 +89,6 @@ The gem version is specified in the Rakefile.
85
89
 
86
90
  ### Copyright
87
91
 
88
- Copyright (c) 2014 Julik Tarkhanov for WeTransfer. See LICENSE.txt for
92
+ Copyright (c) 2014 WeTransfer. See LICENSE.txt for
89
93
  further details.
90
94
 
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ require 'rake'
13
13
 
14
14
  require 'jeweler'
15
15
  Jeweler::Tasks.new do |gem|
16
- gem.version = '1.1.0'
16
+ gem.version = '1.2.0'
17
17
  # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
18
18
  gem.name = "activerecord_autoreplica"
19
19
  gem.homepage = "http://github.com/WeTransfer/activerecord_autoreplica"
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: activerecord_autoreplica 1.1.0 ruby lib
5
+ # stub: activerecord_autoreplica 1.2.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "activerecord_autoreplica"
9
- s.version = "1.1.0"
9
+ s.version = "1.2.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Julik Tarkhanov"]
14
- s.date = "2015-10-19"
14
+ s.date = "2016-10-23"
15
15
  s.description = " Redirect all SELECT queries to a separate connection within a block "
16
16
  s.email = "me@julik.nl"
17
17
  s.extra_rdoc_files = [
@@ -20,7 +20,8 @@ Gem::Specification.new do |s|
20
20
  ]
21
21
  s.files = [
22
22
  ".document",
23
- ".gitlab-ci.yml",
23
+ ".travis.yml",
24
+ ".yardopts",
24
25
  "Gemfile",
25
26
  "LICENSE.txt",
26
27
  "README.md",
@@ -28,13 +29,14 @@ Gem::Specification.new do |s|
28
29
  "activerecord_autoreplica.gemspec",
29
30
  "gemfiles/Gemfile.rails-3.2.x",
30
31
  "gemfiles/Gemfile.rails-4.1.x",
32
+ "gemfiles/Gemfile.rails-5.0.x",
31
33
  "lib/activerecord_autoreplica.rb",
32
34
  "spec/activerecord_autoreplica_spec.rb",
33
35
  "spec/helper.rb"
34
36
  ]
35
37
  s.homepage = "http://github.com/WeTransfer/activerecord_autoreplica"
36
38
  s.licenses = ["MIT"]
37
- s.rubygems_version = "2.2.2"
39
+ s.rubygems_version = "2.4.5.1"
38
40
  s.summary = "Palatable-size read replica adapter for ActiveRecord"
39
41
 
40
42
  if s.respond_to? :specification_version then
@@ -42,6 +44,8 @@ Gem::Specification.new do |s|
42
44
 
43
45
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
46
  s.add_runtime_dependency(%q<activerecord>, ["> 3.0"])
47
+ s.add_development_dependency(%q<rake>, ["~> 10.0"])
48
+ s.add_development_dependency(%q<yard>, [">= 0"])
45
49
  s.add_development_dependency(%q<sqlite3>, [">= 0"])
46
50
  s.add_development_dependency(%q<rspec>, ["~> 2.4"])
47
51
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
@@ -49,6 +53,8 @@ Gem::Specification.new do |s|
49
53
  s.add_development_dependency(%q<jeweler>, [">= 0"])
50
54
  else
51
55
  s.add_dependency(%q<activerecord>, ["> 3.0"])
56
+ s.add_dependency(%q<rake>, ["~> 10.0"])
57
+ s.add_dependency(%q<yard>, [">= 0"])
52
58
  s.add_dependency(%q<sqlite3>, [">= 0"])
53
59
  s.add_dependency(%q<rspec>, ["~> 2.4"])
54
60
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
@@ -57,6 +63,8 @@ Gem::Specification.new do |s|
57
63
  end
58
64
  else
59
65
  s.add_dependency(%q<activerecord>, ["> 3.0"])
66
+ s.add_dependency(%q<rake>, ["~> 10.0"])
67
+ s.add_dependency(%q<yard>, [">= 0"])
60
68
  s.add_dependency(%q<sqlite3>, [">= 0"])
61
69
  s.add_dependency(%q<rspec>, ["~> 2.4"])
62
70
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
@@ -4,6 +4,7 @@ gem 'activerecord', "~> 3"
4
4
  # Add dependencies to develop your gem here.
5
5
  # Include everything needed to run rake, tests, features, etc.
6
6
  group :development do
7
+ gem 'rake', '~> 10.0'
7
8
  gem 'sqlite3'
8
9
  gem "rspec", "~> 2.4"
9
10
  gem "rdoc", "~> 3.12"
@@ -4,6 +4,7 @@ gem 'activerecord', "~> 4"
4
4
  # Add dependencies to develop your gem here.
5
5
  # Include everything needed to run rake, tests, features, etc.
6
6
  group :development do
7
+ gem 'rake', '~> 10.0'
7
8
  gem 'sqlite3'
8
9
  gem "rspec", "~> 2.4"
9
10
  gem "rdoc", "~> 3.12"
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ gem 'activerecord', "~> 5"
3
+
4
+ # Add dependencies to develop your gem here.
5
+ # Include everything needed to run rake, tests, features, etc.
6
+ group :development do
7
+ gem 'rake', '~> 10.0'
8
+ gem 'sqlite3'
9
+ gem "rspec", "~> 2.4"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.0"
12
+ gem "jeweler", "1.8.4" # The last without Nokogiri
13
+ end
@@ -32,8 +32,22 @@
32
32
  # Once the block exits, the original connection handler is reassigned to the AR connection_pool.
33
33
  module AutoReplica
34
34
  # The first one is used in ActiveRecord 3+, the second one in 4+
35
- ConnectionSpecification = ActiveRecord::Base::ConnectionSpecification rescue ActiveRecord::ConnectionAdapters::ConnectionSpecification
36
-
35
+ ConnectionSpecification = begin
36
+ ActiveRecord::Base::ConnectionSpecification
37
+ rescue
38
+ ActiveRecord::ConnectionAdapters::ConnectionSpecification
39
+ end
40
+
41
+ # Runs a given block with all SELECT statements being executed against the read slave
42
+ # database.
43
+ #
44
+ # AutoReplica.using_read_replica_at(:adapter => 'mysql2', :datbase => 'read_replica', ...) do
45
+ # customer = Customer.find(3) # Will SELECT from the replica database at the connection spec passed to the block
46
+ # customer.register_complaint! # Will UPDATE to the master database connection
47
+ # end
48
+ #
49
+ # @param replica_connection_spec_hash_or_url[String, Hash] an ActiveRecord connection specification or a DSN URL
50
+ # @return [void]
37
51
  def self.using_read_replica_at(replica_connection_spec_hash_or_url)
38
52
  return yield if @in_replica_context # This method should not be reentrant
39
53
 
@@ -60,8 +74,12 @@ module AutoReplica
60
74
  end
61
75
  end
62
76
 
63
- # Resolve an ActiveRecord connection URL
77
+ # Resolve an ActiveRecord connection URL, from a string to a Hash.
78
+ #
79
+ # @param url_string[String] the connection URL (like `sqlite3://...`)
80
+ # @return [Hash] a symbol-keyed ActiveRecord connection specification
64
81
  def self.resolve_connection_url(url_string)
82
+ # TODO: privatize this method.
65
83
  if defined?(ActiveRecord::Base::ConnectionSpecification::Resolver) # AR3
66
84
  resolver = ActiveRecord::Base::ConnectionSpecification::Resolver.new(url_string, {})
67
85
  resolver.send(:connection_url_to_hash, url_string) # Because making this public was so hard
@@ -80,7 +98,11 @@ module AutoReplica
80
98
  # We need to maintain our own pool for read replica connections,
81
99
  # aside from the one managed by Rails proper.
82
100
  adapter_method = "%s_connection" % connection_specification_hash[:adapter]
83
- connection_specification = ConnectionSpecification.new(connection_specification_hash, adapter_method)
101
+ connection_specification = begin
102
+ ConnectionSpecification.new('autoreplica', connection_specification_hash, adapter_method)
103
+ rescue ArgumentError # AR 4 and lower wants 2 arguments
104
+ ConnectionSpecification.new(connection_specification_hash, adapter_method)
105
+ end
84
106
  @read_pool = ActiveRecord::ConnectionAdapters::ConnectionPool.new(connection_specification)
85
107
  end
86
108
 
@@ -147,4 +169,11 @@ module AutoReplica
147
169
  @master_connection.public_send(method_name, *args, &blk)
148
170
  end
149
171
  end
172
+
173
+ # if respond_to?(:private_constant)
174
+ # private_constant :ConnectionSpecification
175
+ # private_constant :ConnectionHandler
176
+ # private_constant :Adapter
177
+ # end
178
+
150
179
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord_autoreplica
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julik Tarkhanov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-19 00:00:00.000000000 Z
11
+ date: 2016-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - ">"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: yard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: sqlite3
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -103,7 +131,8 @@ extra_rdoc_files:
103
131
  - README.md
104
132
  files:
105
133
  - ".document"
106
- - ".gitlab-ci.yml"
134
+ - ".travis.yml"
135
+ - ".yardopts"
107
136
  - Gemfile
108
137
  - LICENSE.txt
109
138
  - README.md
@@ -111,6 +140,7 @@ files:
111
140
  - activerecord_autoreplica.gemspec
112
141
  - gemfiles/Gemfile.rails-3.2.x
113
142
  - gemfiles/Gemfile.rails-4.1.x
143
+ - gemfiles/Gemfile.rails-5.0.x
114
144
  - lib/activerecord_autoreplica.rb
115
145
  - spec/activerecord_autoreplica_spec.rb
116
146
  - spec/helper.rb
@@ -134,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
164
  version: '0'
135
165
  requirements: []
136
166
  rubyforge_project:
137
- rubygems_version: 2.2.2
167
+ rubygems_version: 2.4.5.1
138
168
  signing_key:
139
169
  specification_version: 4
140
170
  summary: Palatable-size read replica adapter for ActiveRecord
data/.gitlab-ci.yml DELETED
@@ -1,28 +0,0 @@
1
- # This file is generated by GitLab CI
2
- rake-ar4:
3
- script:
4
- - "apt-get update && apt-get install -y libsqlite3-dev"
5
- - git submodule update --init
6
- - ls -la
7
- - gem install bundler
8
- - apt-get install libsqlite3-dev -y
9
- - bundle config --global jobs 4
10
- - bundle config --global path /cache/gems
11
- - bundle config build.nokogiri "--use-system-libraries --with-xml2-include=/usr/include/libxml2"
12
- - BUNDLE_GEMFILE=gemfiles/Gemfile.rails-4.1.x bundle install
13
- - BUNDLE_GEMFILE=gemfiles/Gemfile.rails-4.1.x bundle exec rake
14
- tags:
15
- - ruby
16
- rake-ar3:
17
- script:
18
- - "apt-get update && apt-get install -y libsqlite3-dev"
19
- - git submodule update --init
20
- - ls -la
21
- - gem install bundler
22
- - bundle config --global jobs 4
23
- - bundle config --global path /cache/gems
24
- - bundle config build.nokogiri "--use-system-libraries --with-xml2-include=/usr/include/libxml2"
25
- - BUNDLE_GEMFILE=gemfiles/Gemfile.rails-3.2.x bundle install
26
- - BUNDLE_GEMFILE=gemfiles/Gemfile.rails-3.2.x bundle exec rake
27
- tags:
28
- - ruby