switchman 1.7.2 → 1.7.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
  SHA1:
3
- metadata.gz: 5cbebb58633ecf7d7de5aee0392cfcc1a4f878ce
4
- data.tar.gz: 0960e8a987a8f278450a25112287feac197560fe
3
+ metadata.gz: 8ac20dcf634164e03ce0325d01a492a6b9f37ea6
4
+ data.tar.gz: c6e4c46ce8b9dbc04a39678cbd892e7f4ab1e852
5
5
  SHA512:
6
- metadata.gz: 3b4229a603a2276b36d20ccaf4c5ccd8517692ccc2afb8d7097222cc8bdccbc6a4de2c39fce95ece6f440b93c3a0124d27eaa10926d0ead5d0f564db82c586e9
7
- data.tar.gz: adad3ed4f5ca5fef5152f2a3aadb6004df803a7b1697820409d11b79a9cb50739412f7e86fe23739ad68006b18eaab1e921183b68c34ea236f5283056dd9c664
6
+ metadata.gz: aed3e8db98ce052fbd21cead9d100cadc1822d20c5fa37eaee88d91bb25e9caedee72f0ce3f160b3d106359814796b43459a851e71e420cafe2ea1f8181a997a
7
+ data.tar.gz: 0f25cdd4c7c85f4ffd6d7c32ebfc0262d2c9593788ebebaaf71d970cfaa947ea47ba2bf40fc9d4834f06b941586ba355123cfd99952367a23b95ba68cb0829ae
@@ -2,12 +2,7 @@ module Switchman
2
2
  module ActiveRecord
3
3
  module Association
4
4
  def shard
5
- if @reflection.options[:polymorphic] || @reflection.klass.shard_category == @owner.class.shard_category
6
- # polymorphic associations assume the same shard as the owning item
7
- @owner.shard
8
- else
9
- Shard.default
10
- end
5
+ reflection.shard(owner)
11
6
  end
12
7
 
13
8
  def build_record(*args)
@@ -42,8 +37,10 @@ module Switchman
42
37
 
43
38
  module CollectionAssociation
44
39
  def get_records
45
- shards = reflection.options[:multishard] && owner.respond_to?(:associated_shards) ? owner.associated_shards : [owner.shard]
46
- Shard.with_each_shard(shards, [klass.shard_category]) do
40
+ shards = reflection.options[:multishard] && owner.respond_to?(:associated_shards) ? owner.associated_shards : [shard]
41
+ # activate both the owner and the target's shard category, so that Reflection#join_id_for,
42
+ # when called for the owner, will be returned relative to shard the query will execute on
43
+ Shard.with_each_shard(shards, [klass.shard_category, owner.class.shard_category].uniq) do
47
44
  super
48
45
  end
49
46
  end
@@ -1,6 +1,17 @@
1
1
  module Switchman
2
2
  module ActiveRecord
3
3
  module Reflection
4
+ module AbstractReflection
5
+ def shard(owner)
6
+ if polymorphic? || klass.shard_category == owner.class.shard_category
7
+ # polymorphic associations assume the same shard as the owning item
8
+ owner.shard
9
+ else
10
+ Shard.default
11
+ end
12
+ end
13
+ end
14
+
4
15
  module AssociationReflection
5
16
  # removes memoization - ActiveRecord::ModelSchema does that anyway;
6
17
  # and in fact this is the exact change AR makes in 4.2+
@@ -21,7 +32,7 @@ module Switchman
21
32
  if polymorphic?
22
33
  key = [key, owner._read_attribute(@foreign_type)]
23
34
  end
24
- key = [key, owner.shard.id].flatten
35
+ key = [key, shard(owner).id].flatten
25
36
  @association_scope_cache[key] ||= @scope_lock.synchronize {
26
37
  @association_scope_cache[key] ||= yield
27
38
  }
@@ -132,6 +132,11 @@ module Switchman
132
132
  ::ActiveRecord::ConnectionAdapters::QueryCache.send(:remove_method, :select_all)
133
133
 
134
134
  ::ActiveRecord::LogSubscriber.prepend(ActiveRecord::LogSubscriber)
135
+ if ::Rails.version >= '4.2'
136
+ ::ActiveRecord::Reflection::AbstractReflection.include(ActiveRecord::Reflection::AbstractReflection)
137
+ else
138
+ ::ActiveRecord::Reflection::AssociationReflection.include(ActiveRecord::Reflection::AbstractReflection)
139
+ end
135
140
  ::ActiveRecord::Reflection::AssociationReflection.prepend(ActiveRecord::Reflection::AssociationReflection)
136
141
  ::ActiveRecord::Relation.prepend(ActiveRecord::Batches)
137
142
  ::ActiveRecord::Relation.prepend(ActiveRecord::Calculations)
@@ -1,3 +1,3 @@
1
1
  module Switchman
2
- VERSION = "1.7.2"
2
+ VERSION = "1.7.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switchman
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.2
4
+ version: 1.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-10-11 00:00:00.000000000 Z
13
+ date: 2016-10-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties
@@ -254,7 +254,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
254
254
  version: '0'
255
255
  requirements: []
256
256
  rubyforge_project:
257
- rubygems_version: 2.6.4
257
+ rubygems_version: 2.5.1
258
258
  signing_key:
259
259
  specification_version: 4
260
260
  summary: Rails 4 sharding magic