octoball 0.1.8 → 0.1.9
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 +4 -4
- data/.github/workflows/rspec.yml +3 -3
- data/lib/octoball/association.rb +3 -6
- data/lib/octoball/current_shard_tracker.rb +1 -1
- data/lib/octoball/log_subscriber.rb +2 -2
- data/lib/octoball/persistence.rb +1 -2
- data/lib/octoball/relation_proxy.rb +9 -11
- data/lib/octoball/using_shard.rb +2 -2
- data/lib/octoball/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: edf38b936ff98ea6c1ca5ceef00f67c33c0cf79f66cd4541999d5071b4364629
|
|
4
|
+
data.tar.gz: b6b385dbc74bdb498f94b6d61bf529cc9d89f2d2ac21b4e411db61504ae6c8b2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a6bea44ca7cfb357ad35f6090f0efed3434da75924895cbab125268b4900bd7e5d7c00414c8cb256b6ecddbd6f6e42cc2bb7a06443942e506a9793e6490c2f0c
|
|
7
|
+
data.tar.gz: ab20e4a63e2744a85c75f9b9625677cd37bfd216e66f33b23de98ae8fc9a89cfd862264e5ba3ec4393e77a89e0c52cf3d756c60b1230ca15ea5d80504b469d59
|
data/.github/workflows/rspec.yml
CHANGED
|
@@ -5,7 +5,7 @@ jobs:
|
|
|
5
5
|
runs-on: ubuntu-latest
|
|
6
6
|
services:
|
|
7
7
|
mysql:
|
|
8
|
-
image: mysql:
|
|
8
|
+
image: mysql:8
|
|
9
9
|
ports:
|
|
10
10
|
- 3306:3306
|
|
11
11
|
env:
|
|
@@ -17,7 +17,7 @@ jobs:
|
|
|
17
17
|
strategy:
|
|
18
18
|
fail-fast: true
|
|
19
19
|
matrix:
|
|
20
|
-
ruby: ["3.2", "3.3", "3.4"]
|
|
20
|
+
ruby: ["3.2", "3.3", "3.4", "4.0"]
|
|
21
21
|
rails: ["7.2", "8.0", "8.1"]
|
|
22
22
|
env:
|
|
23
23
|
BUNDLE_GEMFILE: .github/gemfiles/rails_${{ matrix.rails }}.gemfile
|
|
@@ -25,7 +25,7 @@ jobs:
|
|
|
25
25
|
RAILS_ENV: test
|
|
26
26
|
steps:
|
|
27
27
|
- name: Checkout
|
|
28
|
-
uses: actions/checkout@
|
|
28
|
+
uses: actions/checkout@v6
|
|
29
29
|
- name: Setup ruby
|
|
30
30
|
uses: ruby/setup-ruby@v1
|
|
31
31
|
with:
|
data/lib/octoball/association.rb
CHANGED
|
@@ -15,7 +15,7 @@ class Octoball
|
|
|
15
15
|
[:writer, :ids_reader, :ids_writer, :create, :create!,
|
|
16
16
|
:build, :include?, :load_target, :reload, :size, :select].each do |method|
|
|
17
17
|
class_eval <<-"END", __FILE__, __LINE__ + 1
|
|
18
|
-
def #{method}(
|
|
18
|
+
def #{method}(...)
|
|
19
19
|
shard = owner.current_shard
|
|
20
20
|
return super if !shard || shard == ActiveRecord::Base.current_shard
|
|
21
21
|
ret = nil
|
|
@@ -27,7 +27,6 @@ class Octoball
|
|
|
27
27
|
end
|
|
28
28
|
ret
|
|
29
29
|
end
|
|
30
|
-
ruby2_keywords(:#{method}) if respond_to?(:ruby2_keywords, true)
|
|
31
30
|
END
|
|
32
31
|
end
|
|
33
32
|
end
|
|
@@ -51,13 +50,12 @@ class Octoball
|
|
|
51
50
|
:destroy, :destroy_all, :empty?, :find, :first, :include?, :last, :length,
|
|
52
51
|
:many?, :pluck, :replace, :select, :size, :sum, :to_a, :uniq].each do |method|
|
|
53
52
|
class_eval <<-"END", __FILE__, __LINE__ + 1
|
|
54
|
-
def #{method}(
|
|
53
|
+
def #{method}(...)
|
|
55
54
|
return super if !@association.owner.current_shard || @association.owner.current_shard == ActiveRecord::Base.current_shard
|
|
56
55
|
ActiveRecord::Base.connected_to(shard: @association.owner.current_shard, role: Octoball.current_role) do
|
|
57
56
|
super
|
|
58
57
|
end
|
|
59
58
|
end
|
|
60
|
-
ruby2_keywords(:#{method}) if respond_to?(:ruby2_keywords, true)
|
|
61
59
|
END
|
|
62
60
|
end
|
|
63
61
|
end
|
|
@@ -65,13 +63,12 @@ class Octoball
|
|
|
65
63
|
module ShardedSingularAssociation
|
|
66
64
|
[:reload, :writer, :create, :create!, :build].each do |method|
|
|
67
65
|
class_eval <<-"END", __FILE__, __LINE__ + 1
|
|
68
|
-
def #{method}(
|
|
66
|
+
def #{method}(...)
|
|
69
67
|
return super if !owner.current_shard || owner.current_shard == ActiveRecord::Base.current_shard
|
|
70
68
|
ActiveRecord::Base.connected_to(shard: owner.current_shard, role: Octoball.current_role) do
|
|
71
69
|
super
|
|
72
70
|
end
|
|
73
71
|
end
|
|
74
|
-
ruby2_keywords(:#{method}) if respond_to?(:ruby2_keywords, true)
|
|
75
72
|
END
|
|
76
73
|
end
|
|
77
74
|
end
|
|
@@ -11,9 +11,9 @@ class Octoball
|
|
|
11
11
|
|
|
12
12
|
private
|
|
13
13
|
|
|
14
|
-
def debug(progname = nil, &
|
|
14
|
+
def debug(progname = nil, &)
|
|
15
15
|
conn = current_shard ? color("[Shard: #{current_shard}]", ActiveSupport::LogSubscriber::GREEN, bold: true) : ''
|
|
16
|
-
super(conn + progname.to_s, &
|
|
16
|
+
super(conn + progname.to_s, &)
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
end
|
data/lib/octoball/persistence.rb
CHANGED
|
@@ -7,13 +7,12 @@ class Octoball
|
|
|
7
7
|
[:update_columns, :increment!, :reload, :_delete_row, :_touch_row, :_update_row, :_create_record,
|
|
8
8
|
:transaction, :with_transaction_returning_status].each do |method|
|
|
9
9
|
class_eval <<-"END", __FILE__, __LINE__ + 1
|
|
10
|
-
def #{method}(
|
|
10
|
+
def #{method}(...)
|
|
11
11
|
return super if !current_shard || current_shard == ActiveRecord::Base.current_shard
|
|
12
12
|
ActiveRecord::Base.connected_to(shard: current_shard, role: Octoball.current_role) do
|
|
13
13
|
super
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
|
-
ruby2_keywords(:#{method}) if respond_to?(:ruby2_keywords, true)
|
|
17
16
|
END
|
|
18
17
|
end
|
|
19
18
|
|
|
@@ -33,26 +33,25 @@ class Octoball
|
|
|
33
33
|
end + [:each, :map, :index_by]
|
|
34
34
|
ENUM_WITH_BLOCK_METHODS = [:find, :select, :none?, :any?, :one?, :many?, :sum]
|
|
35
35
|
|
|
36
|
-
def method_missing(method,
|
|
36
|
+
def method_missing(method, ...)
|
|
37
37
|
# raise NoMethodError unless the method is defined in @rel
|
|
38
|
-
return @rel.public_send(method,
|
|
38
|
+
return @rel.public_send(method, ...) unless @rel.respond_to?(method)
|
|
39
39
|
|
|
40
40
|
preamble = <<-EOS
|
|
41
|
-
def #{method}(
|
|
42
|
-
return @rel.#{method}(
|
|
41
|
+
def #{method}(*, **, &mblock)
|
|
42
|
+
return @rel.#{method}(*, **, &mblock) unless @current_shard
|
|
43
43
|
EOS
|
|
44
44
|
postamble = <<-EOS
|
|
45
45
|
return ret unless ret.is_a?(::ActiveRecord::Relation) || ret.is_a?(::ActiveRecord::QueryMethods::WhereChain) || ret.is_a?(::Enumerator)
|
|
46
46
|
::Octoball::RelationProxy.new(ret, @current_shard)
|
|
47
47
|
end
|
|
48
|
-
ruby2_keywords(:#{method}) if respond_to?(:ruby2_keywords, true)
|
|
49
48
|
EOS
|
|
50
49
|
connected_to = '::ActiveRecord::Base.connected_to(role: ::Octoball.current_role, shard: @current_shard)'
|
|
51
50
|
|
|
52
51
|
if ENUM_METHODS.include?(method)
|
|
53
52
|
::Octoball::RelationProxy.class_eval <<-EOS, __FILE__, __LINE__ - 1
|
|
54
53
|
#{preamble}
|
|
55
|
-
ret = #{connected_to} { @rel.to_a }.#{method}(
|
|
54
|
+
ret = #{connected_to} { @rel.to_a }.#{method}(*, **, &mblock)
|
|
56
55
|
#{postamble}
|
|
57
56
|
EOS
|
|
58
57
|
elsif ENUM_WITH_BLOCK_METHODS.include?(method)
|
|
@@ -60,9 +59,9 @@ class Octoball
|
|
|
60
59
|
#{preamble}
|
|
61
60
|
ret = nil
|
|
62
61
|
if mblock
|
|
63
|
-
ret = #{connected_to} { @rel.to_a }.#{method}(
|
|
62
|
+
ret = #{connected_to} { @rel.to_a }.#{method}(*, **, &mblock)
|
|
64
63
|
else
|
|
65
|
-
#{connected_to} { ret = @rel.#{method}(
|
|
64
|
+
#{connected_to} { ret = @rel.#{method}(*, **, &mblock); nil } # return nil to avoid loading relation
|
|
66
65
|
end
|
|
67
66
|
#{postamble}
|
|
68
67
|
EOS
|
|
@@ -70,14 +69,13 @@ class Octoball
|
|
|
70
69
|
::Octoball::RelationProxy.class_eval <<-EOS, __FILE__, __LINE__ - 1
|
|
71
70
|
#{preamble}
|
|
72
71
|
ret = nil
|
|
73
|
-
#{connected_to} { ret = @rel.#{method}(
|
|
72
|
+
#{connected_to} { ret = @rel.#{method}(*, **, &mblock); nil } # return nil to avoid loading relation
|
|
74
73
|
#{postamble}
|
|
75
74
|
EOS
|
|
76
75
|
end
|
|
77
76
|
|
|
78
|
-
public_send(method,
|
|
77
|
+
public_send(method, ...)
|
|
79
78
|
end
|
|
80
|
-
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
|
|
81
79
|
|
|
82
80
|
def inspect
|
|
83
81
|
return @rel.inspect unless @current_shard
|
data/lib/octoball/using_shard.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
class Octoball
|
|
2
|
-
def self.using(shard, &
|
|
3
|
-
ActiveRecord::Base.connected_to(role: current_role, shard: shard&.to_sym, &
|
|
2
|
+
def self.using(shard, &)
|
|
3
|
+
ActiveRecord::Base.connected_to(role: current_role, shard: shard&.to_sym, &)
|
|
4
4
|
end
|
|
5
5
|
|
|
6
6
|
def self.current_role
|
data/lib/octoball/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: octoball
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tomoki Sekiyama
|
|
@@ -169,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
169
169
|
- !ruby/object:Gem::Version
|
|
170
170
|
version: '0'
|
|
171
171
|
requirements: []
|
|
172
|
-
rubygems_version:
|
|
172
|
+
rubygems_version: 4.0.10
|
|
173
173
|
specification_version: 4
|
|
174
174
|
summary: Octopus-like Database Sharding Helper for ActiveRecord 6.1+
|
|
175
175
|
test_files: []
|