switchman 1.8.1 → 1.9.0

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: 50222908649b926ff4aadbe563d555b8e08bb6ef
4
- data.tar.gz: 1ed9670ef0a8e48243f9089f27c8defe49f95f51
3
+ metadata.gz: d2e63c8b9d8a43c1cf8716f775593bc0e5c7296b
4
+ data.tar.gz: c4cda98c0bbdf18d0c648adcf8d8465c90f2246e
5
5
  SHA512:
6
- metadata.gz: 96128751d37b322f381227b2c4326f683a34f1700853001f3a0071c033f584e204677c1d836c129c86cb856005bb321263e9ad5af67160cc7a551a909d894e59
7
- data.tar.gz: 3cda176ecdd6c7857b6e8d1bdfef3c43b08123d665fce3c3d35c2a11c007cc706ee47079e2755192d9a21d6112808bc403fe9e87e259c52c24aa4e5b0aefc68d
6
+ metadata.gz: f2e7e0889dce714d0d128eeca5b09434ba0cd313ebe9e09db2f1d58e7d706e6aa1353e03b54496d2f145fbd19467c74bd095870025eb6fca0321170c06ffd14a
7
+ data.tar.gz: e0614890e323dcedd8b272e1ec571be80de1640d27601d9c905208e4fca69931676ec03e4ef038775aa634e43751909bdf0b18f261fe32b1c8a394764c830d24
@@ -0,0 +1,11 @@
1
+ class AddBackDefaultStringLimitsSwitchman < ActiveRecord::Migration
2
+ def up
3
+ add_string_limit_if_missing :switchman_shards, :name
4
+ add_string_limit_if_missing :switchman_shards, :database_server_id
5
+ end
6
+
7
+ def add_string_limit_if_missing(table, column)
8
+ return if column_exists?(table, column, :string, limit: 255)
9
+ change_column table, column, :string, limit: 255
10
+ end
11
+ end
@@ -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
@@ -52,9 +51,9 @@ module Switchman
52
51
  relation = relation.where(table[primary_key].eq(conditions)) if conditions != :none
53
52
  end
54
53
 
55
- args = [relation, "#{name} Exists"]
56
- args << relation.bind_values
57
- relation.activate { return true if connection.select_value(*args) }
54
+ relation.activate do |shard_rel|
55
+ return true if connection.select_value(shard_rel, "#{name} Exists", shard_rel.bind_values)
56
+ end
58
57
  false
59
58
  end
60
59
  end
@@ -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.1"
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.1
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-11-23 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
@@ -190,6 +190,7 @@ files:
190
190
  - app/models/switchman/shard_internal.rb
191
191
  - db/migrate/20130328212039_create_switchman_shards.rb
192
192
  - db/migrate/20130328224244_create_default_shard.rb
193
+ - db/migrate/20161206323434_add_back_default_string_limits_switchman.rb
193
194
  - lib/switchman.rb
194
195
  - lib/switchman/action_controller/caching.rb
195
196
  - lib/switchman/active_record/abstract_adapter.rb
@@ -217,6 +218,7 @@ files:
217
218
  - lib/switchman/active_record/where_clause_factory.rb
218
219
  - lib/switchman/active_support/cache.rb
219
220
  - lib/switchman/arel.rb
221
+ - lib/switchman/call_super.rb
220
222
  - lib/switchman/connection_pool_proxy.rb
221
223
  - lib/switchman/database_server.rb
222
224
  - lib/switchman/default_shard.rb
@@ -246,7 +248,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
246
248
  requirements:
247
249
  - - ">="
248
250
  - !ruby/object:Gem::Version
249
- version: '2.0'
251
+ version: '2.3'
250
252
  required_rubygems_version: !ruby/object:Gem::Requirement
251
253
  requirements:
252
254
  - - ">="