ebisu_connection 2.4.1 → 3.1.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
- SHA1:
3
- metadata.gz: cecd273a7f108ece25df9eba296918a4240c26e3
4
- data.tar.gz: 123de88d95d7ac6e7327b5f47a369412c15890e2
2
+ SHA256:
3
+ metadata.gz: af07ab35a460c56bc8c229bdd27eb1e0f7dce97ce7841f52944f20f896fc9bc3
4
+ data.tar.gz: 7e4a5fc9e81fd14a69f2ab3736852b4f7316a86f6fbb80175e4081604511a5f0
5
5
  SHA512:
6
- metadata.gz: 19eb6a3075a4fd930fc255ab5178b45442b73f498826d18af8a85955cddf6428fe07d5ab18a3a288df75d8801a82ed807b454a3a52dfc58ba03b4598cb63bb86
7
- data.tar.gz: 0705daf19603c49ed9025a40e43799d730ac72fb81a5526b08d1fa51bc8afb961f7f676bf53b78496d0e92db8003201b005dc8125e713c53f1d3e33e471525e9
6
+ metadata.gz: 0aaf91a886360ff96884d1984a9872c6dbd0928812667e9cd5365fbd6661463743146ab76a3844c13c778b9b4a9aba45a277e087ddf5b43f808afd6ba3bc33b0
7
+ data.tar.gz: cbea4d4af5f6a4988aed983f0bc3392de75da98386c0205b781716d7aa72f5312e1cd8be605f2e926a478f3ea843421a2a4b2206913804c503dcd6222a9ce0ff
@@ -0,0 +1,58 @@
1
+ version: 2.1
2
+
3
+ jobs:
4
+ rspec:
5
+ parameters:
6
+ ruby_version:
7
+ type: string
8
+ gemfile:
9
+ type: string
10
+ docker:
11
+ - image: cimg/ruby:<< parameters.ruby_version >>
12
+ - image: cimg/mysql:8.0
13
+ environment:
14
+ MYSQL_ALLOW_EMPTY_PASSWORD: 'true'
15
+ MYSQL_ROOT_HOST: '%'
16
+ - image: cimg/postgres:14.2
17
+ environment:
18
+ POSTGRES_USER: postgres
19
+ POSTGRES_HOST_AUTH_METHOD: trust
20
+ environment:
21
+ BUNDLE_GEMFILE: gemfiles/<< parameters.gemfile >>
22
+ steps:
23
+ - run:
24
+ name: apt-get install
25
+ command: |
26
+ sudo apt-get update
27
+ sudo apt-get install -y mysql-client
28
+ - run:
29
+ name: wait db
30
+ command: |
31
+ dockerize -wait tcp://127.0.0.1:3306 -wait tcp://127.0.0.1:5432 -timeout 1m
32
+ - checkout
33
+ - run:
34
+ name: "bundle install"
35
+ command: |
36
+ bundle install
37
+ - run:
38
+ name: "run spec"
39
+ command: |
40
+ bundle exec rake test
41
+
42
+ # Invoke jobs via workflows
43
+ # See: https://circleci.com/docs/2.0/configuration-reference/#workflows
44
+ workflows:
45
+ ci:
46
+ jobs:
47
+ - rspec:
48
+ matrix:
49
+ parameters:
50
+ ruby_version: ["2.6", "2.7", "3.0", "3.1"]
51
+ gemfile: ["rails52.gemfile", "rails60.gemfile", "rails61.gemfile"]
52
+ exclude:
53
+ - ruby_version: "2.7"
54
+ gemfile: "rails52.gemfile"
55
+ - ruby_version: "3.0"
56
+ gemfile: "rails52.gemfile"
57
+ - ruby_version: "3.1"
58
+ gemfile: "rails52.gemfile"
data/Appraisals CHANGED
@@ -1,20 +1,20 @@
1
- appraise "rails42" do
2
- gem "activerecord", "~> 4.2.0"
3
- gem 'activesupport', '~> 4.2.0'
4
- gem 'mysql2', '>= 0.3.13', '< 0.5'
5
- gem 'pg', '~> 0.15'
1
+ appraise "rails52" do
2
+ gem 'activerecord', '~> 5.2.0'
3
+ gem 'activesupport', '~> 5.2.0'
4
+ gem 'mysql2', '>= 0.4.4', '< 0.6.0'
5
+ gem 'pg', '>= 0.18', '< 2.0'
6
6
  end
7
7
 
8
- appraise "rails50" do
9
- gem "activerecord", "~> 5.0.0"
10
- gem 'activesupport', '~> 5.0.0'
11
- gem 'mysql2', '>= 0.3.18', '< 0.5'
12
- gem 'pg', '~> 0.18'
8
+ appraise "rails60" do
9
+ gem 'activerecord', '~> 6.0.0'
10
+ gem 'activesupport', '~> 6.0.0'
11
+ gem 'mysql2', '>= 0.4.4', '< 0.6.0'
12
+ gem 'pg', '>= 0.18', '< 2.0'
13
13
  end
14
14
 
15
- appraise "rails51" do
16
- gem 'activerecord', '~> 5.1.0'
17
- gem 'activesupport', '~> 5.1.0'
18
- gem 'mysql2', '>= 0.3.18', '< 0.5'
19
- gem 'pg', '~> 0.18'
15
+ appraise "rails61" do
16
+ gem 'activerecord', '~> 6.1.0'
17
+ gem 'activesupport', '~> 6.1.0'
18
+ gem 'mysql2', '>= 0.4.4', '< 0.6.0'
19
+ gem 'pg', '>= 0.18', '< 2.0'
20
20
  end
data/README.md CHANGED
@@ -50,9 +50,8 @@ article.destory
50
50
  ```
51
51
 
52
52
  ## Support ActiveRecord version
53
- EbisuConnection supports ActiveRecord version 4.2 or later.
54
- If you are using Rails 4.1 or 4.0, you can use EbisuConnection version 2.1.0 or before.
55
- If you are using Rails 3.2, could use EbisuConnection version 1.0.0 or before.
53
+ EbisuConnection supports ActiveRecord version 5.0 or later.
54
+ If you are using Rails 4.2, you can use EbisuConnection version 2.4.2 or before.
56
55
 
57
56
  ## Support DB
58
57
  EbisuConnection supports MySQL and PostgreSQL.
@@ -82,26 +81,27 @@ $ gem install ebisu_connection
82
81
  config/database.yml
83
82
 
84
83
  ```yaml
85
- production:
84
+ default: &default
86
85
  adapter: mysql2
87
86
  encoding: utf8
88
- reconnect: true
89
- database: kaeru
90
- pool: 5
91
- username: master
92
- password: master
93
- host: localhost
94
- socket: /var/run/mysqld/mysqld.sock
87
+ pool: <%%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
88
+ username: root
89
+ password:
90
+
91
+ production:
92
+ <<: *default
93
+ database: blog_production
94
+ username: master_db_user
95
+ password: <%= ENV['MASTER_DATABASE_PASSWORD'] %>
96
+ host: master_db
95
97
 
96
98
  replica:
97
- username: replica
98
- password: replica
99
- host: replica
99
+ username: replica_db_user
100
+ password: <%= ENV['REPLICA_DATABASE_PASSWORD'] %>
100
101
  ```
101
102
 
102
- ```replica``` is a config to connect to replica servers.
103
- Others will use the master server settings.
104
-
103
+ `replica` is the configuration used for connecting read-only queries to the database replica. All other connections will use the database master settings.
104
+
105
105
  Config of each replica server fill out to `config/replica.yml`
106
106
 
107
107
  ```yaml
@@ -123,26 +123,27 @@ String format is it. You can write config with hash.
123
123
  If you may want to user multiple replica group, write multiple replica group to config/database.yml.
124
124
 
125
125
  ```yaml
126
- production:
126
+ default: &default
127
127
  adapter: mysql2
128
128
  encoding: utf8
129
- reconnect: true
130
- database: kaeru
131
- pool: 5
132
- username: master
133
- password: master
134
- host: localhost
135
- socket: /var/run/mysqld/mysqld.sock
129
+ pool: <%%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
130
+ username: root
131
+ password:
132
+
133
+ production:
134
+ <<: *default
135
+ database: blog_production
136
+ username: master_db_user
137
+ password: <%= ENV['MASTER_DATABASE_PASSWORD'] %>
138
+ host: master_db
136
139
 
137
140
  replica:
138
- username: replica
139
- password: replica
140
- host: replica
141
+ username: replica_db_user
142
+ password: <%= ENV['REPLICA_DATABASE_PASSWORD'] %>
141
143
 
142
144
  admin_replica:
143
- username: replica
144
- password: replica
145
- host: admin_replica
145
+ username: admin_replica_db_user
146
+ password: <%= ENV['ADMIN_REPLICA_DATABASE_PASSWORD'] %>
146
147
  ```
147
148
 
148
149
  Config of each replica server fill out to `config/replica.yml`
@@ -160,7 +161,7 @@ production:
160
161
  - "replica5, 20"
161
162
  ```
162
163
 
163
- And call establish_fresh_connection method in model that access to ```admin_replica``` replica group.
164
+ The custom replica stanza can then be applied as an argument to the `establish_fresh_connection` method in the models that should use it. For example:
164
165
 
165
166
  ```ruby
166
167
  class AdminUser < ActiveRecord::Base
@@ -168,7 +169,7 @@ class AdminUser < ActiveRecord::Base
168
169
  end
169
170
  ```
170
171
 
171
- The children is access to same replica group of parent.
172
+ The child (sub) classes of the configured model will inherit the same access as the parent class. Example:
172
173
 
173
174
  ```ruby
174
175
  class Parent < ActiveRecord::Base
@@ -182,10 +183,12 @@ class Benefit < Parent
182
183
  end
183
184
  ```
184
185
 
185
- AdminUser and Benefit access to ```admin_replica``` replica group.
186
+ The `AdminUser` and `Benefit` models will access the database configured for the `admin_replica` group.
187
+
186
188
 
189
+ ### Master-only Models
187
190
 
188
- ### Declare model that doesn't use replica db
191
+ It is possible to declare that specific models always use the DB master for all connections, using the `master_db_only!` method:
189
192
 
190
193
  ```ruby
191
194
  class SomethingModel < ActiveRecord::Base
@@ -193,10 +196,9 @@ class SomethingModel < ActiveRecord::Base
193
196
  end
194
197
  ```
195
198
 
196
- If model that always access to master servers is exist, You may want to write ```master_db_only!``` in model.
197
- The model that master_db_only model's child is always access to master db.
199
+ All queries generated by methods on the `CustomerState` model will be directed to the DB master.
198
200
 
199
- ### for Unicorn
201
+ ### Using EbisuConnection With Unicorn
200
202
 
201
203
  ```ruby
202
204
  before_fork do |server, worker|
@@ -204,12 +206,6 @@ before_fork do |server, worker|
204
206
  ActiveRecord::Base.clear_all_replica_connections!
205
207
  ...
206
208
  end
207
-
208
- after_fork do |server, worker|
209
- ...
210
- ActiveRecord::Base.establish_fresh_connection
211
- ...
212
- end
213
209
  ```
214
210
 
215
211
  ## Contributing
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ namespace :test do
12
12
  Rake::TestTask.new(db) do |t|
13
13
  t.libs << "test"
14
14
  t.libs << "lib"
15
- t.test_files = FileList["test/config/prepare_#{db}", 'test/**/*_test.rb']
15
+ t.test_files = FileList["test/config/prepare_#{db}.rb", 'test/**/*_test.rb']
16
16
  t.verbose = true
17
17
  end
18
18
  end
@@ -19,16 +19,13 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.required_ruby_version = '>= 2.2'
22
+ spec.add_dependency 'fresh_connection', '~> 3.1.0'
23
23
 
24
- spec.add_dependency 'fresh_connection', '~> 2.4.0'
25
- spec.add_dependency 'concurrent-ruby', '~> 1.0.0'
26
-
27
- spec.add_development_dependency 'mysql2', '>= 0.3.13', '< 0.5'
28
- spec.add_development_dependency 'pg', '~> 0.11'
29
- spec.add_development_dependency "bundler", ">= 1.3.0", "< 2.0"
30
- spec.add_development_dependency "rake", ">= 0.8.7"
24
+ spec.add_development_dependency 'mysql2', '>= 0.3.18', '< 0.6.0'
25
+ spec.add_development_dependency 'pg', '>= 0.18', '< 2.0'
26
+ spec.add_development_dependency "bundler"
27
+ spec.add_development_dependency "rake"
31
28
  spec.add_development_dependency 'appraisal'
32
- spec.add_development_dependency "minitest"
29
+ spec.add_development_dependency "minitest", "~> 5.10.0"
33
30
  spec.add_development_dependency "minitest-reporters"
34
31
  end
@@ -0,0 +1,10 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 5.2.0"
6
+ gem "activesupport", "~> 5.2.0"
7
+ gem "mysql2", ">= 0.4.4", "< 0.6.0"
8
+ gem "pg", ">= 0.18", "< 2.0"
9
+
10
+ gemspec path: "../"
@@ -0,0 +1,10 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 6.0.0"
6
+ gem "activesupport", "~> 6.0.0"
7
+ gem "mysql2", ">= 0.4.4", "< 0.6.0"
8
+ gem "pg", ">= 0.18", "< 2.0"
9
+
10
+ gemspec path: "../"
@@ -0,0 +1,10 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 6.1.0"
6
+ gem "activesupport", "~> 6.1.0"
7
+ gem "mysql2", ">= 0.4.4", "< 0.6.0"
8
+ gem "pg", ">= 0.18", "< 2.0"
9
+
10
+ gemspec path: "../"
@@ -0,0 +1,51 @@
1
+ require 'yaml'
2
+
3
+ module EbisuConnection
4
+ class Config
5
+ include Enumerable
6
+
7
+ class << self
8
+ attr_writer :replica_file
9
+
10
+ def config
11
+ return @config if defined?(@config)
12
+
13
+ conf = YAML.load_file(replica_file)
14
+ @config = conf[EbisuConnection.env.to_s] || {}
15
+ end
16
+
17
+ private
18
+
19
+ def replica_file
20
+ return @replica_file if @replica_file
21
+
22
+ raise "nothing replica_file. You have to set a file path using EbisuConnection.replica_file= method" unless defined?(Rails)
23
+
24
+ file = %w(yml yaml).map{|ext| Rails.root.join("config/replica.#{ext}").to_s }.detect {|f| File.exist?(f) }
25
+ return file if file
26
+
27
+ raise "nothing replica_file. You have to put a config/replica.yml file"
28
+ end
29
+ end
30
+
31
+ def initialize(spec_name)
32
+ @conf = load_config(spec_name)
33
+ end
34
+
35
+ def each(&block)
36
+ @conf.each(&block)
37
+ end
38
+
39
+ private
40
+
41
+ def load_config(spec_name)
42
+ c = self.class.config
43
+
44
+ if c.is_a?(Hash)
45
+ c[spec_name] || c
46
+ else
47
+ c
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,6 +1,5 @@
1
- require "concurrent"
2
1
  require "ebisu_connection/replica"
3
- require "ebisu_connection/greatest_common_divisor"
2
+ require "ebisu_connection/load_balancer"
4
3
 
5
4
  module EbisuConnection
6
5
  class ConnectionManager < FreshConnection::AbstractConnectionManager
@@ -9,65 +8,51 @@ module EbisuConnection
9
8
  def initialize(spec_name = nil)
10
9
  super
11
10
 
12
- @replicas = Concurrent::Array.new
13
-
14
- replica_conf.each do |conf|
15
- @replicas << Replica.new(conf, spec_name)
11
+ @replicas = replica_conf.map do |conf|
12
+ Replica.new(conf, spec_name)
16
13
  end
17
-
18
- recalc_roulette
19
14
  end
20
15
 
21
16
  def replica_connection
22
17
  raise AllReplicaHasGoneError if @replicas.empty?
23
- @replicas[@roulette.sample].connection
18
+ load_balancer.replica.connection
24
19
  end
25
20
 
26
21
  def put_aside!
27
- @replicas.each do |pool|
28
- pool.release_connection if pool.active_connection? && !pool.connection.transaction_open?
29
- end
22
+ @replicas.each(&:put_aside!)
30
23
  end
31
24
 
32
25
  def clear_all_connections!
33
- @replicas.each do |pool|
34
- pool.disconnect!
35
- end
26
+ @replicas.each(&:disconnect!)
36
27
  end
37
28
 
38
29
  def recovery?
39
- dead_replicas = @replicas.select do |pool|
40
- c = pool.connection rescue nil
30
+ dead_replicas = @replicas.select do |replica|
31
+ c = replica.connection rescue nil
41
32
  !c || !c.active?
42
33
  end
34
+
43
35
  return false if dead_replicas.empty?
44
36
 
45
- dead_replicas.each do |pool|
46
- pool.disconnect!
47
- @replicas.delete(pool)
37
+ dead_replicas.each do |replica|
38
+ replica.disconnect!
39
+ @replicas.delete(replica)
48
40
  end
49
41
 
50
42
  raise AllReplicaHasGoneError if @replicas.empty?
51
43
 
52
- recalc_roulette
44
+ @load_balancer = nil
53
45
  true
54
46
  end
55
47
 
56
48
  private
57
49
 
58
- def recalc_roulette
59
- weight_list = @replicas.map {|pool| pool.weight }
60
-
61
- @roulette = []
62
- gcd = GreatestCommonDivisor.calc(weight_list)
63
- weight_list.each_with_index do |w, index|
64
- weight = w / gcd
65
- @roulette.concat([index] * weight)
66
- end
50
+ def load_balancer
51
+ @load_balancer ||= LoadBalancer.new(@replicas)
67
52
  end
68
53
 
69
54
  def replica_conf
70
- ConfFile.replica_conf(spec_name)
55
+ @replica_conf ||= Config.new(spec_name)
71
56
  end
72
57
  end
73
58
  end
@@ -0,0 +1,32 @@
1
+ require "ebisu_connection/greatest_common_divisor"
2
+
3
+ module EbisuConnection
4
+ class LoadBalancer
5
+ def initialize(replicas)
6
+ @replicas = replicas
7
+ end
8
+
9
+ def replica
10
+ @replicas[roulette.sample]
11
+ end
12
+
13
+ private
14
+
15
+ def roulette
16
+ @roulette ||= calc_roulette
17
+ end
18
+
19
+ def calc_roulette
20
+ set = []
21
+ weight_list = @replicas.map(&:weight)
22
+ gcd = GreatestCommonDivisor.calc(weight_list)
23
+
24
+ weight_list.each_with_index do |w, index|
25
+ weight = w / gcd
26
+ set.concat([index] * weight)
27
+ end
28
+
29
+ set
30
+ end
31
+ end
32
+ end
@@ -28,6 +28,13 @@ module EbisuConnection
28
28
  def connection
29
29
  @pool.connection
30
30
  end
31
+
32
+ def put_aside!
33
+ return unless active_connection?
34
+ return if connection.transaction_open?
35
+
36
+ release_connection
37
+ end
31
38
 
32
39
  def active_connection?
33
40
  @pool.active_connection?
@@ -1,3 +1,3 @@
1
1
  module EbisuConnection
2
- VERSION = "2.4.1"
2
+ VERSION = "3.1.0"
3
3
  end
@@ -1,17 +1,13 @@
1
1
  require 'active_support'
2
2
  require "fresh_connection"
3
- require "ebisu_connection/conf_file"
3
+ require "ebisu_connection/config"
4
4
 
5
5
  module EbisuConnection
6
6
  class << self
7
7
  attr_writer :env
8
8
 
9
9
  def replica_file=(file)
10
- ConfFile.replica_file = file
11
- end
12
-
13
- def slaves_file=(file)
14
- ConfFile.slaves_file = file
10
+ Config.replica_file = file
15
11
  end
16
12
 
17
13
  def env
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ebisu_connection
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.1
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tsukasaoishi
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-06 00:00:00.000000000 Z
11
+ date: 2022-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fresh_connection
@@ -16,96 +16,82 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.4.0
19
+ version: 3.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.4.0
27
- - !ruby/object:Gem::Dependency
28
- name: concurrent-ruby
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: 1.0.0
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: 1.0.0
26
+ version: 3.1.0
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: mysql2
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - ">="
46
32
  - !ruby/object:Gem::Version
47
- version: 0.3.13
33
+ version: 0.3.18
48
34
  - - "<"
49
35
  - !ruby/object:Gem::Version
50
- version: '0.5'
36
+ version: 0.6.0
51
37
  type: :development
52
38
  prerelease: false
53
39
  version_requirements: !ruby/object:Gem::Requirement
54
40
  requirements:
55
41
  - - ">="
56
42
  - !ruby/object:Gem::Version
57
- version: 0.3.13
43
+ version: 0.3.18
58
44
  - - "<"
59
45
  - !ruby/object:Gem::Version
60
- version: '0.5'
46
+ version: 0.6.0
61
47
  - !ruby/object:Gem::Dependency
62
48
  name: pg
63
49
  requirement: !ruby/object:Gem::Requirement
64
50
  requirements:
65
- - - "~>"
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0.18'
54
+ - - "<"
66
55
  - !ruby/object:Gem::Version
67
- version: '0.11'
56
+ version: '2.0'
68
57
  type: :development
69
58
  prerelease: false
70
59
  version_requirements: !ruby/object:Gem::Requirement
71
60
  requirements:
72
- - - "~>"
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0.18'
64
+ - - "<"
73
65
  - !ruby/object:Gem::Version
74
- version: '0.11'
66
+ version: '2.0'
75
67
  - !ruby/object:Gem::Dependency
76
68
  name: bundler
77
69
  requirement: !ruby/object:Gem::Requirement
78
70
  requirements:
79
71
  - - ">="
80
72
  - !ruby/object:Gem::Version
81
- version: 1.3.0
82
- - - "<"
83
- - !ruby/object:Gem::Version
84
- version: '2.0'
73
+ version: '0'
85
74
  type: :development
86
75
  prerelease: false
87
76
  version_requirements: !ruby/object:Gem::Requirement
88
77
  requirements:
89
78
  - - ">="
90
79
  - !ruby/object:Gem::Version
91
- version: 1.3.0
92
- - - "<"
93
- - !ruby/object:Gem::Version
94
- version: '2.0'
80
+ version: '0'
95
81
  - !ruby/object:Gem::Dependency
96
82
  name: rake
97
83
  requirement: !ruby/object:Gem::Requirement
98
84
  requirements:
99
85
  - - ">="
100
86
  - !ruby/object:Gem::Version
101
- version: 0.8.7
87
+ version: '0'
102
88
  type: :development
103
89
  prerelease: false
104
90
  version_requirements: !ruby/object:Gem::Requirement
105
91
  requirements:
106
92
  - - ">="
107
93
  - !ruby/object:Gem::Version
108
- version: 0.8.7
94
+ version: '0'
109
95
  - !ruby/object:Gem::Dependency
110
96
  name: appraisal
111
97
  requirement: !ruby/object:Gem::Requirement
@@ -124,16 +110,16 @@ dependencies:
124
110
  name: minitest
125
111
  requirement: !ruby/object:Gem::Requirement
126
112
  requirements:
127
- - - ">="
113
+ - - "~>"
128
114
  - !ruby/object:Gem::Version
129
- version: '0'
115
+ version: 5.10.0
130
116
  type: :development
131
117
  prerelease: false
132
118
  version_requirements: !ruby/object:Gem::Requirement
133
119
  requirements:
134
- - - ">="
120
+ - - "~>"
135
121
  - !ruby/object:Gem::Version
136
- version: '0'
122
+ version: 5.10.0
137
123
  - !ruby/object:Gem::Dependency
138
124
  name: minitest-reporters
139
125
  requirement: !ruby/object:Gem::Requirement
@@ -155,8 +141,8 @@ executables: []
155
141
  extensions: []
156
142
  extra_rdoc_files: []
157
143
  files:
144
+ - ".circleci/config.yml"
158
145
  - ".gitignore"
159
- - ".travis.yml"
160
146
  - Appraisals
161
147
  - CODE_OF_CONDUCT.md
162
148
  - Gemfile
@@ -167,20 +153,21 @@ files:
167
153
  - bin/setup
168
154
  - bin/test
169
155
  - ebisu_connection.gemspec
170
- - gemfiles/rails42.gemfile
171
- - gemfiles/rails50.gemfile
172
- - gemfiles/rails51.gemfile
156
+ - gemfiles/rails52.gemfile
157
+ - gemfiles/rails60.gemfile
158
+ - gemfiles/rails61.gemfile
173
159
  - lib/ebisu_connection.rb
174
- - lib/ebisu_connection/conf_file.rb
160
+ - lib/ebisu_connection/config.rb
175
161
  - lib/ebisu_connection/connection_manager.rb
176
162
  - lib/ebisu_connection/greatest_common_divisor.rb
163
+ - lib/ebisu_connection/load_balancer.rb
177
164
  - lib/ebisu_connection/replica.rb
178
165
  - lib/ebisu_connection/version.rb
179
166
  homepage: https://github.com/tsukasaoishi/ebisu_connection
180
167
  licenses:
181
168
  - MIT
182
169
  metadata: {}
183
- post_install_message:
170
+ post_install_message:
184
171
  rdoc_options: []
185
172
  require_paths:
186
173
  - lib
@@ -188,16 +175,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
188
175
  requirements:
189
176
  - - ">="
190
177
  - !ruby/object:Gem::Version
191
- version: '2.2'
178
+ version: '0'
192
179
  required_rubygems_version: !ruby/object:Gem::Requirement
193
180
  requirements:
194
181
  - - ">="
195
182
  - !ruby/object:Gem::Version
196
183
  version: '0'
197
184
  requirements: []
198
- rubyforge_project:
199
- rubygems_version: 2.6.13
200
- signing_key:
185
+ rubygems_version: 3.2.15
186
+ signing_key:
201
187
  specification_version: 4
202
188
  summary: EbisuConnection supports connections with configured replica servers.
203
189
  test_files: []
data/.travis.yml DELETED
@@ -1,23 +0,0 @@
1
- language: ruby
2
- before_install:
3
- - gem install bundler
4
- services:
5
- - mysql
6
- - postgresql
7
- before_script:
8
- - bundle update
9
- - cp test/config/database_postgresql.yml.travis test/config/database_postgresql.yml
10
- - psql -c 'create database ebisu_connection_test_master;' -U postgres
11
- - psql -c 'create database ebisu_connection_test_replica;' -U postgres
12
- cache: bundler
13
- rvm:
14
- - 2.2.7
15
- - 2.3.4
16
- - 2.4.1
17
- gemfile:
18
- - gemfiles/rails42.gemfile
19
- - gemfiles/rails50.gemfile
20
- - gemfiles/rails51.gemfile
21
- matrix:
22
- fast_finish: true
23
- bundler_args: --jobs 3 --retry 3
@@ -1,10 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 4.2.0"
6
- gem "activesupport", "~> 4.2.0"
7
- gem "mysql2", ">= 0.3.13", "< 0.5"
8
- gem "pg", "~> 0.15"
9
-
10
- gemspec path: "../"
@@ -1,10 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 5.0.0"
6
- gem "activesupport", "~> 5.0.0"
7
- gem "mysql2", ">= 0.3.18", "< 0.5"
8
- gem "pg", "~> 0.18"
9
-
10
- gemspec path: "../"
@@ -1,10 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 5.1.0"
6
- gem "activesupport", "~> 5.1.0"
7
- gem "mysql2", ">= 0.3.18", "< 0.5"
8
- gem "pg", "~> 0.18"
9
-
10
- gemspec path: "../"
@@ -1,64 +0,0 @@
1
- require 'yaml'
2
- require 'active_support/deprecation'
3
-
4
- module EbisuConnection
5
- class ConfFile
6
- class << self
7
- attr_writer :replica_file
8
-
9
- def slaves_file=(file)
10
- ActiveSupport::Deprecation.warn(
11
- "'slaves_file=' is deprecated and will removed from version 2.5.0. use 'replica_file=' instead."
12
- )
13
-
14
- self.replica_file = file
15
- end
16
-
17
- def replica_conf(spec_name)
18
- return config unless config.is_a?(Hash)
19
-
20
- c = config[spec_name]
21
- return c if c
22
-
23
- if spec_name == "replica" && config.key?("slave")
24
- ActiveSupport::Deprecation.warn(
25
- "'slave' in replica.yml is deprecated and will ignored from version 2.5.0. use 'replica' insted."
26
- )
27
-
28
- c = config["slave"]
29
- end
30
-
31
- c || config
32
- end
33
-
34
- private
35
-
36
- def config
37
- return @config if defined?(@config)
38
-
39
- conf = YAML.load_file(replica_file)
40
- @config = conf[EbisuConnection.env.to_s] || {}
41
- end
42
-
43
- def replica_file
44
- return @replica_file if @replica_file
45
-
46
- raise "nothing replica_file. You have to set a file path using EbisuConnection.replica_file= method" unless defined?(Rails)
47
-
48
- file = %w(yml yaml).map{|ext| Rails.root.join("config/replica.#{ext}").to_s }.detect {|f| File.exist?(f) }
49
- return file if file
50
-
51
- file = %w(yml yaml).map{|ext| Rails.root.join("config/slave.#{ext}").to_s }.detect {|f| File.exist?(f) }
52
- if file
53
- ActiveSupport::Deprecation.warn(
54
- "file name 'config/#{file}' is deprecated and will ignored from version 2.5.0. use 'config/replica.yml' insted."
55
- )
56
-
57
- return file
58
- end
59
-
60
- raise "nothing replica_file. You have to put a config/replica.yml file"
61
- end
62
- end
63
- end
64
- end