switchman 1.8.2 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b82772037360a02f9f5767314b7f2a5619bb272a
4
- data.tar.gz: b229555c12ad2f2af3527b5018d9a7c437eca543
3
+ metadata.gz: d2e63c8b9d8a43c1cf8716f775593bc0e5c7296b
4
+ data.tar.gz: c4cda98c0bbdf18d0c648adcf8d8465c90f2246e
5
5
  SHA512:
6
- metadata.gz: 43e22952d819b022f6a525e3be7a79acbe8b4e7edf215713833c72a59d12e9a50ae155f46f511295d5ab5177746f9593f8e5dfda729cf747993780a2ee362cfb
7
- data.tar.gz: e6e23bca697932bd9ac28828ffe3fd1c4a3a38db691c68a7cc569a720d01729811a98029eca3f8a5339ebb3d821544a0a8f14b289d76b927c32398d0b1110555
6
+ metadata.gz: f2e7e0889dce714d0d128eeca5b09434ba0cd313ebe9e09db2f1d58e7d706e6aa1353e03b54496d2f145fbd19467c74bd095870025eb6fca0321170c06ffd14a
7
+ data.tar.gz: e0614890e323dcedd8b272e1ec571be80de1640d27601d9c905208e4fca69931676ec03e4ef038775aa634e43751909bdf0b18f261fe32b1c8a394764c830d24
@@ -1,16 +1,13 @@
1
1
  module Switchman
2
2
  module ActiveRecord
3
3
  module Calculations
4
- CALL_SUPER = Object.new.freeze
5
- private_constant :CALL_SUPER
6
4
 
7
5
  def pluck(*column_names)
8
- return super(*column_names[1..-1]) if column_names.first.equal?(CALL_SUPER)
9
6
  target_shard = Shard.current(klass.shard_category)
10
7
  shard_count = 0
11
8
  result = self.activate do |relation, shard|
12
9
  shard_count += 1
13
- results = relation.pluck(CALL_SUPER, *column_names)
10
+ results = relation.call_super(:pluck, Calculations, *column_names)
14
11
  if column_names.length > 1
15
12
  column_names.each_with_index do |column_name, idx|
16
13
  if klass.sharded_column?(column_name)
@@ -30,13 +27,12 @@ module Switchman
30
27
  result
31
28
  end
32
29
 
33
- def execute_simple_calculation(operation, column_name, distinct, super_method: false)
34
- return super(operation, column_name, distinct) if super_method
30
+ def execute_simple_calculation(operation, column_name, distinct)
35
31
  operation = operation.to_s.downcase
36
32
  if operation == "average"
37
33
  result = calculate_simple_average(column_name, distinct)
38
34
  else
39
- result = self.activate{ |relation| relation.send(:execute_simple_calculation, operation, column_name, distinct, super_method: true) }
35
+ result = self.activate{ |relation| relation.call_super(:execute_simple_calculation, Calculations, operation, column_name, distinct) }
40
36
  if result.is_a?(Array)
41
37
  case operation
42
38
  when "count", "sum"
@@ -1,9 +1,8 @@
1
1
  module Switchman
2
2
  module ActiveRecord
3
3
  module FinderMethods
4
- def find_one(id, call_super: false)
4
+ def find_one(id)
5
5
  return super(id) unless klass.integral_id?
6
- return super(id) if call_super
7
6
 
8
7
  if shard_source_value != :implicit
9
8
  current_shard = Shard.current(klass.shard_category)
@@ -14,7 +13,7 @@ module Switchman
14
13
  # skip the shard if the object can't be on it. unless we're only looking at one shard;
15
14
  # we might be expecting a shadow object
16
15
  next if current_id > Shard::IDS_PER_SHARD && self.all_shards.length > 1
17
- relation.send(:find_one, current_id, call_super: true)
16
+ relation.call_super(:find_one, FinderMethods, current_id)
18
17
  end
19
18
  if result.is_a?(Array)
20
19
  result = result.first
@@ -42,17 +42,15 @@ module Switchman
42
42
  primary_shard.activate(klass.shard_category) { super }
43
43
  end
44
44
 
45
- def explain(super_method: false)
46
- return super() if super_method
47
- self.activate { |relation| relation.explain(super_method: true) }
45
+ def explain
46
+ self.activate { |relation| relation.call_super(:explain, Relation) }
48
47
  end
49
48
 
50
49
  to_a_method = ::Rails.version >= '5' ? :records : :to_a
51
50
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
52
- def #{to_a_method}(super_method: false)
53
- return super() if super_method
51
+ def #{to_a_method}
54
52
  return @records if loaded?
55
- results = self.activate { |relation| relation.#{to_a_method}(super_method: true) }
53
+ results = self.activate { |relation| relation.call_super(#{to_a_method.inspect}, Relation) }
56
54
  case shard_value
57
55
  when Array, ::ActiveRecord::Relation, ::ActiveRecord::Base
58
56
  @records = results
@@ -62,14 +60,10 @@ module Switchman
62
60
  end
63
61
  RUBY
64
62
 
65
- CALL_SUPER = Object.new.freeze
66
- private_constant :CALL_SUPER
67
-
68
- %w{update_all delete_all}.each do |method|
63
+ %I{update_all delete_all}.each do |method|
69
64
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
70
65
  def #{method}(*args)
71
- return super(*args[1..-1]) if args.first.equal?(CALL_SUPER)
72
- result = self.activate { |relation| relation.#{method}(CALL_SUPER, *args) }
66
+ result = self.activate { |relation| relation.call_super(#{method.inspect}, Relation, *args) }
73
67
  result = result.sum if result.is_a?(Array)
74
68
  result
75
69
  end
@@ -0,0 +1,18 @@
1
+ module Switchman
2
+ module CallSuper
3
+ def super_method_above(method_name, above_module)
4
+ @super_methods ||= {}
5
+ @super_methods[[method_name, above_module]] ||= begin
6
+ method = method(method_name)
7
+ while method.owner != above_module
8
+ method = method.super_method
9
+ end
10
+ method.super_method
11
+ end
12
+ end
13
+
14
+ def call_super(method, above_module, *args, &block)
15
+ super_method_above(method, above_module).call(*args, &block)
16
+ end
17
+ end
18
+ end
@@ -84,6 +84,7 @@ module Switchman
84
84
  require "switchman/active_record/type_caster"
85
85
  require "switchman/active_record/where_clause_factory"
86
86
  require "switchman/arel"
87
+ require "switchman/call_super"
87
88
  require "switchman/rails"
88
89
  require "switchman/shackles/relation"
89
90
  require "switchman/shard_internal"
@@ -134,9 +135,10 @@ module Switchman
134
135
  ::ActiveRecord::Relation.prepend(ActiveRecord::Calculations)
135
136
  ::ActiveRecord::Relation.include(ActiveRecord::FinderMethods)
136
137
  ::ActiveRecord::Relation.include(ActiveRecord::QueryMethods)
138
+ ::ActiveRecord::Relation.prepend(Shackles::Relation)
137
139
  ::ActiveRecord::Relation.prepend(ActiveRecord::Relation)
138
140
  ::ActiveRecord::Relation.include(ActiveRecord::SpawnMethods)
139
- ::ActiveRecord::Relation.prepend(Shackles::Relation)
141
+ ::ActiveRecord::Relation.include(CallSuper)
140
142
 
141
143
  if ::Rails.version >= '5'
142
144
  ::ActiveRecord::Relation::WhereClauseFactory.prepend(ActiveRecord::WhereClauseFactory)
@@ -1,3 +1,3 @@
1
1
  module Switchman
2
- VERSION = "1.8.2"
2
+ VERSION = "1.9.0"
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.8.2
4
+ version: 1.9.0
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-12-06 00:00:00.000000000 Z
13
+ date: 2016-12-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties
@@ -218,6 +218,7 @@ files:
218
218
  - lib/switchman/active_record/where_clause_factory.rb
219
219
  - lib/switchman/active_support/cache.rb
220
220
  - lib/switchman/arel.rb
221
+ - lib/switchman/call_super.rb
221
222
  - lib/switchman/connection_pool_proxy.rb
222
223
  - lib/switchman/database_server.rb
223
224
  - lib/switchman/default_shard.rb
@@ -247,7 +248,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
247
248
  requirements:
248
249
  - - ">="
249
250
  - !ruby/object:Gem::Version
250
- version: '2.0'
251
+ version: '2.3'
251
252
  required_rubygems_version: !ruby/object:Gem::Requirement
252
253
  requirements:
253
254
  - - ">="
@@ -255,9 +256,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
255
256
  version: '0'
256
257
  requirements: []
257
258
  rubyforge_project:
258
- rubygems_version: 2.6.7
259
+ rubygems_version: 2.5.2
259
260
  signing_key:
260
261
  specification_version: 4
261
262
  summary: Rails 4 sharding magic
262
263
  test_files: []
263
- has_rdoc: