octoball 0.1.2 → 0.1.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: bb7caa27776a9d9ab8f6136f4a82544be12783a5efb1802e9a2a0b4dfb7f2c61
4
- data.tar.gz: 818225f81822a0b77d4a5bc18ffdd6a11373ae47c6142a22ef8f7de23f61dc4f
3
+ metadata.gz: 79b000766e9d706b1d98717665279bfd6fd7302b6f0e55dd675658cbd5477674
4
+ data.tar.gz: f083a86147e3c7942fbbf042b2f82358576d9b5d2e696e2b4a872a2595eb252f
5
5
  SHA512:
6
- metadata.gz: a8210244af4c7d1cbd92693f89bb68c6a3ed978457d51bbfa9e1d4fb5a6b6ec498649d01d0eb70eb1ba9ae0ea350f0914b05756b275381a6244011fb95f6226a
7
- data.tar.gz: d19f93c68c99e8a0524f13a876f7c742715e7e8303c6d742cd4565837e13b511909312958a716bac1eb4ae22cc22b26b61ffd38c75b18831d5de8594ab9f475d
6
+ metadata.gz: 0c24fa278965d1202d0905f8b37b3d42845789b6e1fe6145426c7a1760c88fec3cb380ce080d5d401b7f951c879055da557d33e3575a2cc06796d517d45dd5af
7
+ data.tar.gz: 7d5e45681650dcbe9aa640242a0c0c86a290e82ca095698f91a56866e527ffcbe113f91a1e764a52a5c720f6c12d210f62900091e7203cbbf9f9d3848886bc8a
@@ -6,7 +6,7 @@ class Octoball
6
6
  end
7
7
 
8
8
  module ShardedCollectionAssociation
9
- [:reader, :writer, :ids_reader, :ids_writer, :create, :create!,
9
+ [:writer, :ids_reader, :ids_writer, :create, :create!,
10
10
  :build, :include?, :load_target, :reload, :size, :select].each do |method|
11
11
  class_eval <<-"END", __FILE__, __LINE__ + 1
12
12
  def #{method}(*args, &block)
@@ -26,6 +26,20 @@ class Octoball
26
26
  end
27
27
  end
28
28
 
29
+ module ShardedCollectionProxyCreate
30
+ def create(klass, association)
31
+ shard = association.owner.current_shard
32
+ return super unless shard
33
+ return RelationProxy.new(super, shard) if shard == ActiveRecord::Base.current_shard
34
+ ret = nil
35
+ ActiveRecord::Base.connected_to(shard: shard, role: Octoball.current_role) do
36
+ ret = RelationProxy.new(super, shard)
37
+ nil # return nil to avoid loading relation
38
+ end
39
+ ret
40
+ end
41
+ end
42
+
29
43
  module ShardedCollectionProxy
30
44
  [:any?, :build, :count, :create, :create!, :concat, :delete, :delete_all,
31
45
  :destroy, :destroy_all, :empty?, :find, :first, :include?, :last, :length,
@@ -43,7 +57,7 @@ class Octoball
43
57
  end
44
58
 
45
59
  module ShardedSingularAssociation
46
- [:reader, :writer, :create, :create!, :build].each do |method|
60
+ [:reload, :writer, :create, :create!, :build].each do |method|
47
61
  class_eval <<-"END", __FILE__, __LINE__ + 1
48
62
  def #{method}(*args, &block)
49
63
  return super if !owner.current_shard || owner.current_shard == ActiveRecord::Base.current_shard
@@ -59,6 +73,7 @@ class Octoball
59
73
  ::ActiveRecord::Relation.prepend(RelationCurrentShard)
60
74
  ::ActiveRecord::QueryMethods::WhereChain.prepend(RelationCurrentShard)
61
75
  ::ActiveRecord::Associations::CollectionAssociation.prepend(ShardedCollectionAssociation)
76
+ ::ActiveRecord::Associations::CollectionProxy.singleton_class.prepend(ShardedCollectionProxyCreate)
62
77
  ::ActiveRecord::Associations::CollectionProxy.prepend(ShardedCollectionProxy)
63
78
  ::ActiveRecord::Associations::SingularAssociation.prepend(ShardedSingularAssociation)
64
79
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Octoball
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
@@ -676,7 +676,7 @@ describe Octoball::ShardedSingularAssociation, :shards => [:brazil, :master, :ca
676
676
 
677
677
  it 'empty?' do
678
678
  expect(@brazil_client.items.empty?).to be false
679
- c = Client.create!(:name => 'Client1')
679
+ c = Client.using(:master).create!(:name => 'Client1')
680
680
  expect(c.items.empty?).to be true
681
681
  end
682
682
 
@@ -893,7 +893,7 @@ describe Octoball::ShardedSingularAssociation, :shards => [:brazil, :master, :ca
893
893
 
894
894
  it 'empty?' do
895
895
  expect(@brazil_client.comments.empty?).to be false
896
- c = Client.create!(:name => 'Client1')
896
+ c = Client.using(:master).create!(:name => 'Client1')
897
897
  expect(c.comments.empty?).to be true
898
898
  end
899
899
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octoball
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomoki Sekiyama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-28 00:00:00.000000000 Z
11
+ date: 2021-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord