ar-octopus-ruby-3 0.11.2 → 0.11.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45148ba25887b36967a31b5b152fca794127f8aed6c9cbe6e510afb9e46a394b
4
- data.tar.gz: 90e3f6c6a6d5df3c596c6e6c7187ac8cd12d0564cdbbc52b257034f0080a1328
3
+ metadata.gz: f9363f5411d262101a505bcc38e95ca6a3cd404d034c03102bf9e21fdaf01877
4
+ data.tar.gz: 8335ef51d85e315c96491d306e22b11e56996b07fee8825c4bc91aedf2c98b1e
5
5
  SHA512:
6
- metadata.gz: 492e656e572b5ce6d402e48bd7210ff305c00c8d61bc1d0fe71a0f9d8e30a590e2aba80bfc3b9a74011bf7ac8b48b83cd197867a1d29d41d4d044179a9196166
7
- data.tar.gz: 27e3f7c9fbdacf8c1e05e7bc6f78f444b53f850b4d18898bf2d29d05cdf70aca2077da772c67bf040357c3f6556fb82399ddb2d7f7dfba5bc848bdf74f17a309
6
+ metadata.gz: 456bcbf510933fec3fd46680ea84c721567b6e2f83ecac7743a8d5e243d3de8e8757136d2033da42af494ee99d9652e78526e568690bd22e0ee013c09388e823
7
+ data.tar.gz: a03cfe1be9d2eac1c13b7b440746ce841fae58e4cfd56638ac605e67d218ec9bd11894035553a50b16e223bd720febbadd232a2a3c79f2def4a9137d924ccc11
data/.gitignore CHANGED
@@ -10,3 +10,4 @@ tmp/*
10
10
  .*.sw[a-z]
11
11
  database.log
12
12
  .byebug_history
13
+ .env
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.0.6
data/Gemfile.lock ADDED
@@ -0,0 +1,102 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ar-octopus-ruby-3 (0.11.2)
5
+ activerecord (~> 6.0.6.1)
6
+ activesupport (~> 6.0.6.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (6.0.6.1)
12
+ activesupport (= 6.0.6.1)
13
+ activerecord (6.0.6.1)
14
+ activemodel (= 6.0.6.1)
15
+ activesupport (= 6.0.6.1)
16
+ activesupport (6.0.6.1)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 0.7, < 2)
19
+ minitest (~> 5.1)
20
+ tzinfo (~> 1.1)
21
+ zeitwerk (~> 2.2, >= 2.2.2)
22
+ appraisal (2.4.1)
23
+ bundler
24
+ rake
25
+ thor (>= 0.14.0)
26
+ ast (2.4.2)
27
+ byebug (11.1.3)
28
+ coderay (1.1.3)
29
+ concurrent-ruby (1.2.2)
30
+ diff-lcs (1.5.0)
31
+ i18n (1.14.1)
32
+ concurrent-ruby (~> 1.0)
33
+ json (2.6.3)
34
+ method_source (1.0.0)
35
+ minitest (5.18.0)
36
+ mysql2 (0.5.5)
37
+ parallel (1.23.0)
38
+ parser (3.2.2.3)
39
+ ast (~> 2.4.1)
40
+ racc
41
+ pg (0.21.0)
42
+ pry (0.14.2)
43
+ coderay (~> 1.1)
44
+ method_source (~> 1.0)
45
+ pry-byebug (3.10.1)
46
+ byebug (~> 11.0)
47
+ pry (>= 0.13, < 0.15)
48
+ racc (1.7.0)
49
+ rainbow (3.1.1)
50
+ rake (13.0.6)
51
+ regexp_parser (2.8.1)
52
+ rexml (3.2.5)
53
+ rspec (3.12.0)
54
+ rspec-core (~> 3.12.0)
55
+ rspec-expectations (~> 3.12.0)
56
+ rspec-mocks (~> 3.12.0)
57
+ rspec-core (3.12.2)
58
+ rspec-support (~> 3.12.0)
59
+ rspec-expectations (3.12.3)
60
+ diff-lcs (>= 1.2.0, < 2.0)
61
+ rspec-support (~> 3.12.0)
62
+ rspec-mocks (3.12.5)
63
+ diff-lcs (>= 1.2.0, < 2.0)
64
+ rspec-support (~> 3.12.0)
65
+ rspec-support (3.12.0)
66
+ rubocop (1.52.1)
67
+ json (~> 2.3)
68
+ parallel (~> 1.10)
69
+ parser (>= 3.2.2.3)
70
+ rainbow (>= 2.2.2, < 4.0)
71
+ regexp_parser (>= 1.8, < 3.0)
72
+ rexml (>= 3.2.5, < 4.0)
73
+ rubocop-ast (>= 1.28.0, < 2.0)
74
+ ruby-progressbar (~> 1.7)
75
+ unicode-display_width (>= 2.4.0, < 3.0)
76
+ rubocop-ast (1.29.0)
77
+ parser (>= 3.2.1.0)
78
+ ruby-progressbar (1.13.0)
79
+ sqlite3 (1.6.3-x86_64-linux)
80
+ thor (1.2.2)
81
+ thread_safe (0.3.6)
82
+ tzinfo (1.2.11)
83
+ thread_safe (~> 0.1)
84
+ unicode-display_width (2.4.2)
85
+ zeitwerk (2.6.8)
86
+
87
+ PLATFORMS
88
+ x86_64-linux
89
+
90
+ DEPENDENCIES
91
+ appraisal (>= 0.3.8)
92
+ ar-octopus-ruby-3!
93
+ mysql2 (~> 0.5)
94
+ pg (~> 0.18)
95
+ pry-byebug
96
+ rake
97
+ rspec (>= 3)
98
+ rubocop
99
+ sqlite3 (~> 1.4)
100
+
101
+ BUNDLED WITH
102
+ 2.4.13
data/Rakefile CHANGED
@@ -16,7 +16,6 @@ namespace :db do
16
16
  :host => 'localhost',
17
17
  :username => (ENV['POSTGRES_USER'] || 'postgres'),
18
18
  :encoding => 'utf8',
19
- :password => ''
20
19
  }
21
20
 
22
21
  mysql_spec = {
@@ -24,7 +23,6 @@ namespace :db do
24
23
  :host => 'localhost',
25
24
  :username => (ENV['MYSQL_USER'] || 'root'),
26
25
  :encoding => 'utf8',
27
- :password => ''
28
26
  }
29
27
 
30
28
  ` rm -f /tmp/database.sqlite3 `
data/ar-octopus.gemspec CHANGED
@@ -25,7 +25,6 @@ Gem::Specification.new do |s|
25
25
 
26
26
  s.add_dependency 'activerecord', "~> 6.0.6.1"
27
27
  s.add_dependency 'activesupport', "~> 6.0.6.1"
28
- # s.add_dependency 'pg', "~> 1.1.0"
29
28
 
30
29
  s.add_development_dependency 'appraisal', '>= 0.3.8'
31
30
  # To install the mysql2 gem its necessary execute the following command before run bundle
data/lib/octopus/proxy.rb CHANGED
@@ -213,17 +213,11 @@ module Octopus
213
213
  def legacy_method_missing_logic(method, *args, &block)
214
214
  if should_clean_connection_proxy?(method)
215
215
  clean_connection_proxy
216
- preparable = check_preparable_arg(args)
216
+ args, preparable = handle_args(args)
217
217
 
218
- args.pop unless preparable.nil?
219
-
220
- if args.present?
221
- val = select_connection.send(method, *args, **preparable, &block)
222
- else
223
- val = select_connection.send(method, *args, &block)
224
- end
225
-
226
- # conn.send(method, *args, &block)
218
+ val = preparable.nil? ?
219
+ select_connection.send(method, *args, &block) :
220
+ select_connection.send(method, *args, **preparable, &block)
227
221
  elsif should_send_queries_to_shard_slave_group?(method)
228
222
  send_queries_to_shard_slave_group(method, *args, &block)
229
223
  elsif should_send_queries_to_slave_group?(method)
@@ -231,15 +225,11 @@ module Octopus
231
225
  elsif should_send_queries_to_replicated_databases?(method)
232
226
  send_queries_to_selected_slave(method, *args, &block)
233
227
  else
234
- preparable = check_preparable_arg(args)
235
-
236
- args.pop unless preparable.nil?
228
+ args, preparable = handle_args(args)
237
229
 
238
- if args.present?
239
- val = select_connection.send(method, *args, **preparable, &block)
240
- else
241
- val = select_connection.send(method, *args, &block)
242
- end
230
+ val = preparable.nil? ?
231
+ select_connection.send(method, *args, &block) :
232
+ select_connection.send(method, *args, **preparable, &block)
243
233
 
244
234
  if val.instance_of? ActiveRecord::Result
245
235
  val.current_shard = shard_name
@@ -249,14 +239,6 @@ module Octopus
249
239
  end
250
240
  end
251
241
 
252
- def check_preparable_arg(args)
253
- selected_hashs = args.select{ |arg| arg.is_a? Hash }.first
254
-
255
- return selected_hashs if selected_hashs.present?
256
-
257
- {preparable: nil}
258
- end
259
-
260
242
  # Ensure that a single failing slave doesn't take down the entire application
261
243
  def with_each_healthy_shard
262
244
  shards.each do |shard_name, v|
@@ -334,15 +316,11 @@ module Octopus
334
316
  # while preserving `current_shard`
335
317
  def send_queries_to_slave(slave, method, *args, &block)
336
318
  using_shard(slave) do
337
- preparable = check_preparable_arg(args)
338
-
339
- args.pop unless preparable.nil?
319
+ args, preparable = handle_args(args)
340
320
 
341
- if args.present?
342
- val = select_connection.send(method, *args, **preparable, &block)
343
- else
344
- val = select_connection.send(method, *args, &block)
345
- end
321
+ val = preparable.nil? ?
322
+ select_connection.send(method, *args, &block) :
323
+ select_connection.send(method, *args, **preparable, &block)
346
324
 
347
325
  if val.instance_of? ActiveRecord::Result
348
326
  val.current_shard = slave
@@ -395,5 +373,17 @@ module Octopus
395
373
  self.current_group = older_group
396
374
  end
397
375
  end
376
+
377
+ private
378
+
379
+ def handle_args(args)
380
+ return [[], nil] if args.empty?
381
+
382
+ preparable_args = args.select{ |arg| arg.is_a?(Hash) && arg.key?(:preparable)}
383
+ return [args, nil] if preparable_args.empty?
384
+
385
+ args -= preparable_args
386
+ return [args, preparable_args.first]
387
+ end
398
388
  end
399
389
  end
@@ -1,3 +1,3 @@
1
1
  module Octopus
2
- VERSION = '0.11.2'
2
+ VERSION = '0.11.3'
3
3
  end
@@ -2,27 +2,27 @@
2
2
  # gem install sqlite3-ruby (not necessary on OS X Leopard)
3
3
  development:
4
4
  adapter: postgresql
5
- username: daniel
6
- password: '1234'
5
+ username: postgres
6
+ password:
7
7
  database: octopus_sample_app_development
8
8
  encoding: unicode
9
- host: ''
9
+ host: localhost
10
10
 
11
11
  # Warning: The database defined as "test" will be erased and
12
12
  # re-generated from your development database when you run "rake".
13
13
  # Do not set this db to the same as development or production.
14
14
  test: &test
15
15
  adapter: postgresql
16
- username: daniel
17
- password: '1234'
16
+ username: postgres
17
+ password:
18
18
  database: octopus_sample_app_test
19
19
  encoding: unicode
20
- host: ''
20
+ host: localhost
21
21
 
22
- # production:
23
- # adapter: postgresql
24
- # username: postgres
25
- # password:
26
- # database: octopus_sample_app_production
27
- # encoding: unicode
28
- # host: localhost
22
+ production:
23
+ adapter: postgresql
24
+ username: postgres
25
+ password:
26
+ database: octopus_sample_app_production
27
+ encoding: unicode
28
+ host: localhost
@@ -2,14 +2,12 @@ mysql: &mysql
2
2
  adapter: mysql2
3
3
  username: <%= ENV['MYSQL_USER'] || 'root' %>
4
4
  host: localhost
5
- password: '1234'
6
5
 
7
6
  mysql_unavailable: &mysql_unavailable
8
7
  adapter: mysql2
9
8
  username: <%= ENV['MYSQL_USER'] || 'root' %>
10
9
  host: 192.0.2.1
11
10
  connect_timeout: 3
12
- password: '1234'
13
11
 
14
12
  octopus: &octopus
15
13
  shards:
@@ -19,11 +17,11 @@ octopus: &octopus
19
17
 
20
18
  postgresql_shard:
21
19
  adapter: postgresql
22
- username: <%= ENV['POSTGRES_USER'] || 'daniel' %>
23
- password: '1234'
20
+ username: <%= ENV['POSTGRES_USER'] || 'postgres' %>
21
+ password:
24
22
  database: octopus_shard_1
25
23
  encoding: unicode
26
- host: ''
24
+ host: localhost
27
25
 
28
26
  sqlite_shard:
29
27
  adapter: sqlite3
@@ -40,7 +40,7 @@ describe Octopus, :shards => [] do
40
40
  expect { User.using(:crazy_shard).create!(:name => 'Joaquim') }.to raise_error(RuntimeError)
41
41
 
42
42
  Octopus.setup do |config|
43
- config.shards = { :crazy_shard => { :adapter => 'mysql2', :database => 'octopus_shard_5', :username => "#{ENV['MYSQL_USER'] || 'root'}", :password => ENV['MYSQL_PASSWORD'] } }
43
+ config.shards = { :crazy_shard => { :adapter => 'mysql2', :database => 'octopus_shard_5', :username => "#{ENV['MYSQL_USER'] || 'root'}", :password => '' } }
44
44
  end
45
45
 
46
46
  expect { User.using(:crazy_shard).create!(:name => 'Joaquim') }.not_to raise_error
@@ -30,7 +30,7 @@ describe Octopus::Proxy do
30
30
  config = proxy.config
31
31
  expect(config[:adapter]).to eq('mysql2')
32
32
  expect(config[:database]).to eq('octopus_shard_1')
33
- expect(config[:username]).to eq("#{ENV['MYSQL_USER'] || 'root'}")
33
+ expect(config[:username]).to eq("#{ENV['MYSQL_USER'] || 'daniel'}")
34
34
  end
35
35
 
36
36
  unless Octopus.rails50? || Octopus.rails51?|| Octopus.rails52? || Octopus.rails60?
@@ -28,7 +28,7 @@ end
28
28
  # This class sets its own connection
29
29
  class CustomConnection < ActiveRecord::Base
30
30
  self.table_name = 'custom'
31
- octopus_establish_connection(:adapter => 'mysql2', :database => 'octopus_shard_2', :username => "#{ENV['MYSQL_USER'] || ''}", :password => '')
31
+ octopus_establish_connection(:adapter => 'mysql2', :database => 'octopus_shard_2', :username => "#{ENV['MYSQL_USER'] || ''}", :password => '1234')
32
32
  end
33
33
 
34
34
  # This items belongs to a client
@@ -39,15 +39,10 @@ module OctopusHelper
39
39
  end
40
40
 
41
41
  def self.migrate_to_version(direction, root, version)
42
+ schema = ActiveRecord::SchemaMigration
43
+ migrations = ActiveRecord::MigrationContext.new(root, schema).migrations.select {|mig| version == mig.version }
42
44
 
43
- if Octopus.atleast_rails52?
44
- migrations = ActiveRecord::MigrationContext.new(root).migrations.select {|mig| version == mig.version }
45
- ActiveRecord::Migrator.new(direction, migrations, version).run
46
- else
47
- schema = ActiveRecord::SchemaMigration
48
- migrations = ActiveRecord::MigrationContext.new(root, schema).migrations.select {|mig| version == mig.version }
49
- ActiveRecord::Migrator.new(direction, migrations, schema, version).run
50
- end
45
+ ActiveRecord::Migrator.new(direction, migrations, schema, version).run
51
46
  end
52
47
 
53
48
  def self.using_environment(environment, &_block)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar-octopus-ruby-3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.2
4
+ version: 0.11.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thiago Pradi
@@ -167,9 +167,11 @@ files:
167
167
  - ".rspec"
168
168
  - ".rubocop.yml"
169
169
  - ".rubocop_todo.yml"
170
+ - ".tool-versions"
170
171
  - ".travis.yml"
171
172
  - Appraisals
172
173
  - Gemfile
174
+ - Gemfile.lock
173
175
  - README.mkdn
174
176
  - Rakefile
175
177
  - TODO.txt