activerecord-turntable 4.0.0 → 4.1.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
- SHA256:
3
- metadata.gz: 5bd7f48754157e32eaaf254a518645b9d1cde4e31840dba63b927886bedb74ee
4
- data.tar.gz: 529f08173f847218298a34ed9832163e1d129b003e8ba0ef201ca63d8333b029
2
+ SHA1:
3
+ metadata.gz: 31aa02feae321af087a80d9a1f9177c0ff7c139a
4
+ data.tar.gz: dbb3b7404067e3a2b756b96eaa5f76a51e27450d
5
5
  SHA512:
6
- metadata.gz: 515cc5103600046d62ea3b91a5695787a2f34d423da084e15aa3dbef8accdba238abd4bb4fb4c4e2659cdbe9ac965f020afb2d6f75a84c4e097cff28e2f1d6cb
7
- data.tar.gz: '0578e2aff069a944a6b512b04ae19d47fe2591813f9666f7324cb7d592a4febaa61b457dd71b75dfe8b592f1666bdf57880a3f552da0702c1362b64126db401c'
6
+ metadata.gz: 3bb4919921852779beb4b1d31f67f524e5985921c5d00d613799417a769c80eeaf3eec5cd51deaa5ea061cdc0869b8295b785806a5febb2ca7979924482ac79b
7
+ data.tar.gz: e5f313cc055e68af9520db17c29edcb717b8459b3ccb65819fe9d17e08010937a938277fc2baafa469b4fb8555a7f8f88a1344cf89064eff3a6d259e2cd6fe12
@@ -5,10 +5,10 @@ cache:
5
5
  bundler: true
6
6
 
7
7
  rvm:
8
- - 2.2.9
9
- - 2.3.6
10
- - 2.4.3
11
- - 2.5.0
8
+ - 2.2.10
9
+ - 2.3.7
10
+ - 2.4.4
11
+ - 2.5.1
12
12
  - ruby-head
13
13
 
14
14
  gemfile:
@@ -18,12 +18,15 @@ gemfile:
18
18
  - gemfiles/rails5_0_3.gemfile
19
19
  - gemfiles/rails5_0_4.gemfile
20
20
  - gemfiles/rails5_0_5.gemfile
21
+ - gemfiles/rails5_0_6.gemfile
22
+ - gemfiles/rails5_0_7.gemfile
21
23
  - gemfiles/rails5_1_0.gemfile
22
24
  - gemfiles/rails5_1_1.gemfile
23
25
  - gemfiles/rails5_1_2.gemfile
24
26
  - gemfiles/rails5_1_3.gemfile
25
27
  - gemfiles/rails5_1_4.gemfile
26
28
  - gemfiles/rails5_1_5.gemfile
29
+ - gemfiles/rails5_1_6.gemfile
27
30
  - gemfiles/rails_edge.gemfile
28
31
 
29
32
  env:
@@ -37,6 +40,7 @@ services:
37
40
  before_install:
38
41
  - docker run -d --name turntable-katsubushi -p 11212:11212 katsubushi/katsubushi:latest -worker-id 1
39
42
  - gem update --system
43
+ - gem install bundler --no-doc
40
44
 
41
45
  before_script:
42
46
  - bundle exec rake $SETUP_TASK
@@ -48,14 +52,19 @@ matrix:
48
52
  exclude:
49
53
  - rvm: ruby-head
50
54
  - gemfile: gemfiles/rails_edge.gemfile
51
- - rvm: 2.3.6
52
- - rvm: 2.4.3
55
+ - rvm: 2.2.10
56
+ - rvm: 2.3.7
57
+ - rvm: 2.4.4
53
58
  include:
54
- - rvm: 2.3.6
55
- gemfile: gemfiles/rails5_1_5.gemfile
56
- - rvm: 2.4.3
57
- gemfile: gemfiles/rails5_1_5.gemfile
58
- - rvm: 2.5.0
59
+ - rvm: 2.2.10
60
+ gemfile: gemfiles/rails5_0_7.gemfile
61
+ - rvm: 2.2.10
62
+ gemfile: gemfiles/rails5_1_6.gemfile
63
+ - rvm: 2.3.7
64
+ gemfile: gemfiles/rails5_1_6.gemfile
65
+ - rvm: 2.4.4
66
+ gemfile: gemfiles/rails5_1_6.gemfile
67
+ - rvm: 2.5.1
59
68
  gemfile: gemfiles/rails_edge.gemfile
60
69
  - rvm: ruby-head
61
70
  gemfile: gemfiles/rails_edge.gemfile
@@ -1,3 +1,15 @@
1
+ ## activerecord-turntable 4.1.0 ##
2
+
3
+ ### Major Changes
4
+
5
+ * Support activerecord versions v5.0.6, v5.0.7 and v5.1.6
6
+ * Remove unneeded monkey patches
7
+ * Add `ActiveRecord::Base.turntable_pool_list` instead of `ActiveRecord::Base.turntable_connections`
8
+
9
+ ### BugFixes
10
+
11
+ * Fix connection leaks on fork
12
+
1
13
  ## activerecord-turntable 4.0.0 ##
2
14
 
3
15
  ### Major Changes
data/Gemfile CHANGED
@@ -2,7 +2,5 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem "activerecord", "~> 5.1.1"
6
- gem "activesupport", "~> 5.1.1"
7
-
8
- gem "mysql2", "~> 0.4.4"
5
+ gem "activerecord", "~> 5.1.6"
6
+ gem "activesupport", "~> 5.1.6"
data/README.md CHANGED
@@ -27,7 +27,7 @@ MySQL only.
27
27
  Add to Gemfile:
28
28
 
29
29
  ```ruby
30
- gem 'activerecord-turntable', '~> 4.0.0'
30
+ gem 'activerecord-turntable', '~> 4.1.0'
31
31
  ```
32
32
 
33
33
  Run a bundle install:
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "activerecord", "5.0.6"
4
+ gem "activesupport", "5.0.6"
5
+
6
+ gem "mysql2", "~> 0.4.4"
7
+
8
+ gemspec :path => '../'
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "activerecord", "5.0.7"
4
+ gem "activesupport", "5.0.7"
5
+
6
+ gemspec :path => '../'
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "activerecord", "5.1.6"
4
+ gem "activesupport", "5.1.6"
5
+ gem "actionview", "5.1.6"
6
+
7
+ gemspec :path => '../'
@@ -27,7 +27,7 @@ module ActiveRecord::Turntable
27
27
  ActiveRecord::Persistence.include(Persistence)
28
28
  ActiveRecord::Locking::Optimistic.include(LockingOptimistic)
29
29
  ActiveRecord::Relation.include(CleverLoad)
30
- ActiveRecord::Relation.prepend(Relation)
30
+ ActiveRecord::Relation.prepend(Relation) unless Util.ar_version_equals_or_later?("5.1.6")
31
31
  ActiveRecord::Migration.include(ActiveRecord::Turntable::Migration)
32
32
  ActiveRecord::ConnectionAdapters::ConnectionHandler.prepend(ConnectionHandlerExtension)
33
33
  ActiveRecord::Associations::Preloader::Association.prepend(AssociationPreloader)
@@ -133,10 +133,5 @@ module ActiveRecord
133
133
  instantiate_fixtures if use_instantiated_fixtures
134
134
  end
135
135
  # rubocop:enable Style/ClassVars, Style/RedundantException
136
-
137
- def enlist_fixture_connections
138
- ActiveRecord::Base.connection_handler.connection_pool_list.map(&:connection) +
139
- ActiveRecord::Base.turntable_connections.values.map(&:connection)
140
- end
141
136
  end
142
137
  end
@@ -1,7 +1,47 @@
1
1
  module ActiveRecord::Turntable
2
2
  module ActiveRecordExt
3
3
  module LockingOptimistic
4
- if Util.ar51_or_later?
4
+ if Util.ar_version_equals_or_later?("5.1.6")
5
+ ::ActiveRecord::Locking::Optimistic.class_eval <<-EOD
6
+ private
7
+ def _update_row(attribute_names, attempted_action = "update")
8
+ return super unless locking_enabled?
9
+
10
+ begin
11
+ locking_column = self.class.locking_column
12
+ previous_lock_value = read_attribute_before_type_cast(locking_column)
13
+ attribute_names << locking_column
14
+
15
+ self[locking_column] += 1
16
+
17
+ constraints = {
18
+ self.class.primary_key => id_in_database,
19
+ locking_column => previous_lock_value
20
+ }
21
+ if self.class.sharding_condition_needed?
22
+ constraints[self.class.turntable_shard_key] = self[self.class.turntable_shard_key]
23
+ end
24
+
25
+ affected_rows = self.class.unscoped._update_record(
26
+ arel_attributes_with_values(attribute_names),
27
+ constraints,
28
+ )
29
+
30
+ if affected_rows != 1
31
+ raise ActiveRecord::StaleObjectError.new(self, attempted_action)
32
+ end
33
+
34
+ affected_rows
35
+
36
+ # If something went wrong, revert the locking_column value.
37
+ rescue Exception
38
+ self[locking_column] = previous_lock_value.to_i
39
+ raise
40
+ end
41
+ end
42
+ EOD
43
+
44
+ elsif Util.ar51_or_later?
5
45
  ::ActiveRecord::Locking::Optimistic.class_eval <<-EOD
6
46
  private
7
47
  # @note Override to add sharding condition on optimistic locking
@@ -20,7 +20,7 @@ module ActiveRecord::Turntable
20
20
 
21
21
  unless (payload[:binds] || []).empty?
22
22
  if Util.ar_version_equals_or_later?("5.0.3")
23
- casted_params = if Util.ar_version_equals_or_later?("5.1.5")
23
+ casted_params = if Util.ar_version_satisfy?(">= 5.1.5") || Util.ar_version_satisfy?([">= 5.0.7", "< 5.1"])
24
24
  type_casted_binds(payload[:type_casted_binds])
25
25
  else
26
26
  type_casted_binds(payload[:binds], payload[:type_casted_binds])
@@ -26,54 +26,56 @@ module ActiveRecord::Turntable
26
26
  self
27
27
  end
28
28
 
29
- # @note Override to add sharding scope on `touch`
30
- # rubocop:disable Style/UnlessElse
31
- def touch(*names, time: nil)
32
- unless persisted?
33
- raise ActiveRecord::ActiveRecordError, <<-MSG.squish
34
- cannot touch on a new or destroyed record object. Consider using
35
- persisted?, new_record?, or destroyed? before touching
36
- MSG
37
- end
29
+ unless Util.ar_version_equals_or_later?("5.1.6")
30
+ # @note Override to add sharding scope on `touch`
31
+ # rubocop:disable Style/UnlessElse
32
+ def touch(*names, time: nil)
33
+ unless persisted?
34
+ raise ActiveRecord::ActiveRecordError, <<-MSG.squish
35
+ cannot touch on a new or destroyed record object. Consider using
36
+ persisted?, new_record?, or destroyed? before touching
37
+ MSG
38
+ end
38
39
 
39
- time ||= current_time_from_proper_timezone
40
- attributes = timestamp_attributes_for_update_in_model
41
- attributes.concat(names)
40
+ time ||= current_time_from_proper_timezone
41
+ attributes = timestamp_attributes_for_update_in_model
42
+ attributes.concat(names)
42
43
 
43
- unless attributes.empty?
44
- changes = {}
44
+ unless attributes.empty?
45
+ changes = {}
45
46
 
46
- attributes.each do |column|
47
- column = column.to_s
48
- changes[column] = write_attribute(column, time)
49
- end
47
+ attributes.each do |column|
48
+ column = column.to_s
49
+ changes[column] = write_attribute(column, time)
50
+ end
50
51
 
51
- clear_attribute_changes(changes.keys) unless Util.ar51_or_later?
52
- primary_key = self.class.primary_key
53
- scope = if turntable_enabled? && primary_key != self.class.turntable_shard_key.to_s
54
- self.class.unscoped.where(self.class.turntable_shard_key => _read_attribute(turntable_shard_key))
55
- else
56
- self.class.unscoped
57
- end
58
- scope = scope.where(primary_key => _read_attribute(primary_key))
59
-
60
- if locking_enabled?
61
- locking_column = self.class.locking_column
62
- scope = scope.where(locking_column => _read_attribute(locking_column))
63
- changes[locking_column] = increment_lock
64
- end
52
+ clear_attribute_changes(changes.keys) unless Util.ar51_or_later?
53
+ primary_key = self.class.primary_key
54
+ scope = if turntable_enabled? && primary_key != self.class.turntable_shard_key.to_s
55
+ self.class.unscoped.where(self.class.turntable_shard_key => _read_attribute(turntable_shard_key))
56
+ else
57
+ self.class.unscoped
58
+ end
59
+ scope = scope.where(primary_key => _read_attribute(primary_key))
65
60
 
66
- clear_attribute_changes(changes.keys) if Util.ar51_or_later?
67
- result = scope.update_all(changes) == 1
61
+ if locking_enabled?
62
+ locking_column = self.class.locking_column
63
+ scope = scope.where(locking_column => _read_attribute(locking_column))
64
+ changes[locking_column] = increment_lock
65
+ end
68
66
 
69
- if !result && locking_enabled?
70
- raise ActiveRecord::StaleObjectError.new(self, "touch")
71
- end
67
+ clear_attribute_changes(changes.keys) if Util.ar51_or_later?
68
+ result = scope.update_all(changes) == 1
72
69
 
73
- @_trigger_update_callback = result
74
- result
75
- else
76
- true
70
+ if !result && locking_enabled?
71
+ raise ActiveRecord::StaleObjectError.new(self, "touch")
72
+ end
73
+
74
+ @_trigger_update_callback = result
75
+ result
76
+ else
77
+ true
78
+ end
77
79
  end
78
80
  end
79
81
  # rubocop:enable Style/UnlessElse
@@ -115,25 +117,39 @@ module ActiveRecord::Turntable
115
117
  relation
116
118
  end
117
119
 
118
- # @note Override to add sharding scope on updating
119
- def _update_record(attribute_names = self.attribute_names)
120
- klass = self.class
121
- attributes_values = arel_attributes_with_values_for_update(attribute_names)
122
- if attributes_values.empty?
123
- rows_affected = 0
124
- @_trigger_update_callback = true
125
- else
126
- scope = if klass.turntable_enabled? && (klass.primary_key != klass.turntable_shard_key.to_s)
127
- klass.unscoped.where(klass.turntable_shard_key => self.send(turntable_shard_key))
128
- end
129
- previous_id = Util.ar51_or_later? ? id_in_database : id_was
130
- rows_affected = klass.unscoped._update_record attributes_values, id, previous_id, scope
131
- @_trigger_update_callback = rows_affected > 0
120
+ if Util.ar_version_equals_or_later?("5.1.6")
121
+ def _update_row(attribute_names, attempted_action = "update")
122
+ constraints = { self.class.primary_key => id_in_database }
123
+ if self.class.sharding_condition_needed?
124
+ constraints[self.class.turntable_shard_key] = self[self.class.turntable_shard_key]
125
+ end
126
+
127
+ self.class.unscoped._update_record(
128
+ arel_attributes_with_values(attribute_names),
129
+ constraints,
130
+ )
131
+ end
132
+ else
133
+ # @note Override to add sharding scope on updating
134
+ def _update_record(attribute_names = self.attribute_names)
135
+ klass = self.class
136
+ attributes_values = arel_attributes_with_values_for_update(attribute_names)
137
+ if attributes_values.empty?
138
+ rows_affected = 0
139
+ @_trigger_update_callback = true
140
+ else
141
+ scope = if klass.turntable_enabled? && (klass.primary_key != klass.turntable_shard_key.to_s)
142
+ klass.unscoped.where(klass.turntable_shard_key => self.send(turntable_shard_key))
143
+ end
144
+ previous_id = Util.ar51_or_later? ? id_in_database : id_was
145
+ rows_affected = klass.unscoped._update_record attributes_values, id, previous_id, scope
146
+ @_trigger_update_callback = rows_affected > 0
147
+ end
148
+
149
+ yield(self) if block_given?
150
+
151
+ rows_affected
132
152
  end
133
-
134
- yield(self) if block_given?
135
-
136
- rows_affected
137
153
  end
138
154
  end
139
155
  end
@@ -14,7 +14,7 @@ module ActiveRecord::Turntable
14
14
  def run
15
15
  result = super
16
16
 
17
- pools = ActiveRecord::Base.turntable_connections.values
17
+ pools = ActiveRecord::Base.turntable_pool_list
18
18
  pools.each do |pool|
19
19
  pool.enable_query_cache!
20
20
  end
@@ -36,7 +36,7 @@ module ActiveRecord::Turntable
36
36
  def run
37
37
  result = super
38
38
 
39
- pools = ActiveRecord::Base.turntable_connections.values
39
+ pools = ActiveRecord::Base.turntable_pool_list
40
40
  pools.each do |pool|
41
41
  pool.enable_query_cache!
42
42
  end
@@ -58,7 +58,7 @@ module ActiveRecord::Turntable
58
58
  def run
59
59
  result = super
60
60
 
61
- pools = ActiveRecord::Base.turntable_connections.values
61
+ pools = ActiveRecord::Base.turntable_pool_list
62
62
  pools.each do |k|
63
63
  k.connection.enable_query_cache!
64
64
  end
@@ -70,7 +70,7 @@ module ActiveRecord::Turntable
70
70
  enabled, _connection_id = state
71
71
  super
72
72
 
73
- klasses = ActiveRecord::Base.turntable_connections.values
73
+ klasses = ActiveRecord::Base.turntable_pool_list
74
74
  klasses.each do |k|
75
75
  k.connection.clear_query_cache
76
76
  k.connection.disable_query_cache! unless enabled
@@ -5,10 +5,9 @@ module ActiveRecord::Turntable
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  included do
8
- class_attribute :turntable_connections, :turntable_clusters, :turntable_sequencers,
8
+ class_attribute :turntable_clusters, :turntable_sequencers,
9
9
  :turntable_enabled, :turntable_sequencer_enabled, :turntable_configuration
10
10
 
11
- self.turntable_connections = {}
12
11
  self.turntable_clusters = {}.with_indifferent_access
13
12
  self.turntable_sequencers = {}.with_indifferent_access
14
13
  self.turntable_enabled = false
@@ -52,6 +51,10 @@ module ActiveRecord::Turntable
52
51
  turntable_clusters[turntable_cluster_name]
53
52
  end
54
53
 
54
+ def turntable_pool_list
55
+ turntable_clusters.values.map { |cluster| cluster.shards.map(&:connection_pool) }.flatten.uniq
56
+ end
57
+
55
58
  def turntable_replace_connection_pool
56
59
  ch = connection_handler
57
60
  cp = ConnectionProxy.new(self, turntable_cluster)
@@ -61,10 +64,6 @@ module ActiveRecord::Turntable
61
64
  ch.send(:owner_to_pool)[connection_specification_name] = pp
62
65
  end
63
66
 
64
- def clear_all_connections!
65
- turntable_connections.values.each(&:disconnect!)
66
- end
67
-
68
67
  def sequencer(sequencer_name, *args)
69
68
  class_attribute :turntable_sequencer_name
70
69
  class << self
@@ -83,6 +82,10 @@ module ActiveRecord::Turntable
83
82
  turntable_enabled
84
83
  end
85
84
 
85
+ def sharding_condition_needed?
86
+ turntable_enabled? && primary_key != turntable_shard_key.to_s
87
+ end
88
+
86
89
  def sequencer_enabled?
87
90
  turntable_sequencer_enabled
88
91
  end
@@ -13,9 +13,9 @@ module ActiveRecord::Turntable
13
13
  module ClassMethods
14
14
  def force_transaction_all_shards!(options = {}, &block)
15
15
  force_connect_all_shards!
16
- shards = turntable_connections.values
17
- shards += [ActiveRecord::Base.connection_pool]
18
- recursive_transaction(shards, options, &block)
16
+ pools = turntable_pool_list
17
+ pools += [ActiveRecord::Base.connection_pool]
18
+ recursive_transaction(pools, options, &block)
19
19
  end
20
20
 
21
21
  def recursive_transaction(pools, options, &block)
@@ -30,16 +30,7 @@ module ActiveRecord::Turntable
30
30
  end
31
31
 
32
32
  def force_connect_all_shards!
33
- conf = configurations[::ActiveRecord::ConnectionHandling::DEFAULT_ENV.call.to_sym]
34
- return unless conf
35
-
36
- shards = HashWithIndifferentAccess.new
37
- shards = shards.merge(conf[:shards]) if conf[:shards]
38
- shards = shards.merge(conf[:seq]) if conf[:seq]
39
- shards.each do |name, config|
40
- turntable_connections[name] ||=
41
- ActiveRecord::ConnectionAdapters::ConnectionPool.new(spec_for(config))
42
- end
33
+ turntable_pool_list.each(&:connection)
43
34
  end
44
35
 
45
36
  def spec_for(config)
@@ -59,16 +59,16 @@ module ActiveRecord::Turntable
59
59
  def enable_query_cache!
60
60
  default_connection.enable_query_cache!
61
61
 
62
- klass.turntable_connections.each do |_k, v|
63
- v.connection.enable_query_cache!
62
+ cluster.shards.each do |shard|
63
+ shard.connection.enable_query_cache!
64
64
  end
65
65
  end
66
66
 
67
67
  def disable_query_cache!
68
68
  default_connection.disable_query_cache!
69
69
 
70
- klass.turntable_connections.each do |_k, v|
71
- v.connection.disable_query_cache!
70
+ cluster.shards.each do |shard|
71
+ shard.connection.disable_query_cache!
72
72
  end
73
73
  end
74
74
 
@@ -79,12 +79,11 @@ module ActiveRecord::Turntable
79
79
  def clear_query_cache
80
80
  default_connection.clear_query_cache
81
81
 
82
- klass.turntable_connections.each do |_k, v|
83
- v.connection.clear_query_cache
82
+ cluster.shards.each do |shard|
83
+ shard.connection.clear_query_cache
84
84
  end
85
85
  end
86
86
 
87
-
88
87
  # rubocop:disable Style/MethodMissing
89
88
  def method_missing(method, *args, &block)
90
89
  clear_query_cache_if_needed(method)
@@ -10,10 +10,15 @@ module ActiveRecord::Turntable
10
10
 
11
11
  private
12
12
 
13
- def create_connection_class
14
- klass = connection_class_instance
15
- klass.remove_connection
16
- klass.establish_connection ActiveRecord::Base.connection_pool.spec.config[:seq][name].with_indifferent_access
13
+ def connection_class_instance
14
+ if Connections.const_defined?(name.classify)
15
+ klass = Connections.const_get(name.classify)
16
+ else
17
+ klass = Class.new(ActiveRecord::Base)
18
+ Connections.const_set(name.classify, klass)
19
+ klass.abstract_class = true
20
+ klass.establish_connection ActiveRecord::Base.connection_pool.spec.config[:seq][name].with_indifferent_access
21
+ end
17
22
  klass
18
23
  end
19
24
  end
@@ -11,7 +11,6 @@ module ActiveRecord::Turntable
11
11
  @cluster = cluster
12
12
  @name = name
13
13
  @slaves = slaves.map { |s| SlaveShard.new(cluster, s) }
14
- ActiveRecord::Base.turntable_connections[name] = connection_pool
15
14
  end
16
15
 
17
16
  def connection_pool
@@ -43,14 +42,7 @@ module ActiveRecord::Turntable
43
42
  private
44
43
 
45
44
  def connection_klass
46
- @connection_klass ||= create_connection_class
47
- end
48
-
49
- def create_connection_class
50
- klass = connection_class_instance
51
- klass.remove_connection
52
- klass.establish_connection ActiveRecord::Base.connection_pool.spec.config[:shards][name].with_indifferent_access
53
- klass
45
+ @connection_klass ||= connection_class_instance
54
46
  end
55
47
 
56
48
  def connection_class_instance
@@ -60,6 +52,7 @@ module ActiveRecord::Turntable
60
52
  klass = Class.new(ActiveRecord::Base)
61
53
  Connections.const_set(name.classify, klass)
62
54
  klass.abstract_class = true
55
+ klass.establish_connection ActiveRecord::Base.connection_pool.spec.config[:shards][name].with_indifferent_access
63
56
  end
64
57
  klass
65
58
  end
@@ -12,6 +12,13 @@ module ActiveRecord::Turntable
12
12
  ActiveRecord.gem_version.release
13
13
  end
14
14
 
15
+ def ar_version_satisfy?(requirement)
16
+ unless requirement.is_a?(Gem::Requirement)
17
+ requirement = Gem::Requirement.new(requirement)
18
+ end
19
+ requirement.satisfied_by?(ar_version)
20
+ end
21
+
15
22
  def ar51_or_later?
16
23
  ar_version_equals_or_later?("5.1")
17
24
  end
@@ -19,6 +26,7 @@ module ActiveRecord::Turntable
19
26
  module_function :ar_version_equals_or_later?,
20
27
  :ar_version_earlier_than?,
21
28
  :ar_version,
29
+ :ar_version_satisfy?,
22
30
  :ar51_or_later?
23
31
  end
24
32
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module Turntable
3
- VERSION = "4.0.0".freeze
3
+ VERSION = "4.1.0".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-turntable
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - gussan
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-04-03 00:00:00.000000000 Z
12
+ date: 2018-04-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -529,12 +529,15 @@ files:
529
529
  - gemfiles/rails5_0_3.gemfile
530
530
  - gemfiles/rails5_0_4.gemfile
531
531
  - gemfiles/rails5_0_5.gemfile
532
+ - gemfiles/rails5_0_6.gemfile
533
+ - gemfiles/rails5_0_7.gemfile
532
534
  - gemfiles/rails5_1_0.gemfile
533
535
  - gemfiles/rails5_1_1.gemfile
534
536
  - gemfiles/rails5_1_2.gemfile
535
537
  - gemfiles/rails5_1_3.gemfile
536
538
  - gemfiles/rails5_1_4.gemfile
537
539
  - gemfiles/rails5_1_5.gemfile
540
+ - gemfiles/rails5_1_6.gemfile
538
541
  - gemfiles/rails_edge.gemfile
539
542
  - lib/active_record/turntable.rb
540
543
  - lib/active_record/turntable/active_record_ext.rb
@@ -632,7 +635,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
632
635
  version: '0'
633
636
  requirements: []
634
637
  rubyforge_project: activerecord-turntable
635
- rubygems_version: 2.7.6
638
+ rubygems_version: 2.6.14
636
639
  signing_key:
637
640
  specification_version: 4
638
641
  summary: ActiveRecord sharding extension