active_record_mutex 3.2.0 → 3.2.1

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: 34e4fb422fbe0336eee934df7fdeb49843c4b0335fe4222db9d8df1728b7d477
4
- data.tar.gz: c3dc8c6fe86409160ded37ed5941cef3033d03b82e60c630c950ade50fc1d901
3
+ metadata.gz: 36b8a40a6140ecdfcd0e3892d2e008d502acdce96826ef3aecc797cadb65fa89
4
+ data.tar.gz: 38bf80d5ed330479f5a8399633048c606f7d03b71aaccacf512509c9cdcbb58e
5
5
  SHA512:
6
- metadata.gz: bd1437072b603f1dd5641d70970fe3bd2a24e77862a88d035222b4b1c0c360eb99ce14a573be87fc2e331e85955283262380be09c709e3bad936944a36b6615a
7
- data.tar.gz: 2f4528e9a7d63ce3e2f9584f0b0099c783b07bf518174fd50c107237e0ad994fed77519f408ef27daa3aa752d3df1452fdc7a0139a312c21fe6d708d77cc5f0c
6
+ metadata.gz: a580eda2be88864af2b8aec078b09b5757992063f9078e64afb195c167bfc6b858f1d0674f2c348e66659c9f759e2cb47bb147a9b6118e9817510cdf6b77cb05
7
+ data.tar.gz: 51e00870718236b49c3271a0164d68fe6708e5b2451daad87b9f211090b3d7979a06546665d25082dadaca028fbb773c544ac33f7932c3a8d04150c2e31ff369
data/CHANGES.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changes
2
2
 
3
+ ## 2024-10-16 v3.2.1
4
+
5
+ * Refactor DatabaseMutex implementation:
6
+ * Change `@name` and `mutex.name` to downcase and freeze values
7
+ * Update tests to reflect new behavior
8
+
9
+ ## 2024-10-16 v3.2.0
10
+
11
+ * DatabaseMutex improvements:
12
+ * Improved lock name generation in `lock_name` method.
13
+ * Modified SQL queries to use `lock_name` instead of `internal_name`.
14
+ * Added `lock_exists?` and `test_all_mutexes` methods for testing mutex
15
+ creation and querying.
16
+
3
17
  ## 2024-10-16 v3.1.0
4
18
 
5
19
  * Changes for **3.1.0**:
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: active_record_mutex 3.2.0 ruby lib
2
+ # stub: active_record_mutex 3.2.1 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "active_record_mutex".freeze
6
- s.version = "3.2.0".freeze
6
+ s.version = "3.2.1".freeze
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
@@ -20,9 +20,10 @@ module ActiveRecord
20
20
  #
21
21
  # @raise [ ArgumentError ] if no **name** option is provided in the options hash.
22
22
  def initialize(opts = {})
23
- @name = opts[:name].to_s
23
+ @name = opts[:name].to_s.downcase
24
24
  @name.size != 0 or raise ArgumentError, "mutex requires a nonempty :name argument"
25
- internal_name # create/check internal_name
25
+ @name.freeze
26
+ lock_name # create/check internal_name and lock_name
26
27
  end
27
28
 
28
29
  # Returns the name of this mutex as given via the constructor argument.
@@ -35,7 +36,8 @@ module ActiveRecord
35
36
  def internal_name
36
37
  @internal_name and return @internal_name
37
38
  encoded_name = ?$ + Digest::MD5.base64digest([ self.class.name, name ] * ?#).
38
- delete('^A-Za-z0-9+/').gsub(/[+\/]/, ?+ => ?_, ?/ => ?.)
39
+ delete('^A-Za-z0-9+/').gsub(/[+\/]/, ?+ => ?_, ?/ => ?.).
40
+ downcase.freeze
39
41
  if encoded_name.size <= 64
40
42
  @internal_name = encoded_name
41
43
  else
@@ -50,8 +52,11 @@ module ActiveRecord
50
52
  #
51
53
  # @return [ String ] the generated lock name
52
54
  def lock_name
55
+ @lock_name and return @lock_name
53
56
  prefix_name = name.gsub(/[^[:print:]]/, '')[0, 32]
54
- prefix_name + ?= + internal_name
57
+ @lock_name = prefix_name + ?= + internal_name
58
+ @lock_name.downcase!
59
+ @lock_name.freeze
55
60
  end
56
61
 
57
62
  # The synchronize method attempts to acquire a mutex lock for the given name
@@ -1,6 +1,6 @@
1
1
  module ActiveRecord::DatabaseMutex
2
2
  # ActiveRecord::DatabaseMutex version
3
- VERSION = '3.2.0'
3
+ VERSION = '3.2.1'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -25,7 +25,7 @@ class DatabaseMutexTest < Test::Unit::TestCase
25
25
  old, ENV['RAILS_ENV'] = ENV['RAILS_ENV'], nil
26
26
  mutex = Foo.mutex
27
27
  assert_kind_of ActiveRecord::DatabaseMutex::Implementation, mutex
28
- assert_equal Foo.name, mutex.name
28
+ assert_equal Foo.name.downcase, mutex.name
29
29
  ensure
30
30
  ENV['RAILS_ENV'] = old
31
31
  end
@@ -34,7 +34,7 @@ class DatabaseMutexTest < Test::Unit::TestCase
34
34
  old, ENV['RAILS_ENV'] = ENV['RAILS_ENV'], 'test'
35
35
  mutex = Foo.mutex
36
36
  assert_kind_of ActiveRecord::DatabaseMutex::Implementation, mutex
37
- assert_equal "#{Foo.name}@test", mutex.name
37
+ assert_equal "#{Foo.name}@test".downcase, mutex.name
38
38
  ensure
39
39
  ENV['RAILS_ENV'] = old
40
40
  end
@@ -47,7 +47,7 @@ class DatabaseMutexTest < Test::Unit::TestCase
47
47
  assert_equal true, instance.save
48
48
  mutex = instance.mutex
49
49
  assert_kind_of ActiveRecord::DatabaseMutex::Implementation, mutex
50
- assert_equal "#{instance.id}@#{Foo.name}", mutex.name
50
+ assert_equal "#{instance.id}@#{Foo.name}".downcase, mutex.name
51
51
  end
52
52
 
53
53
  def test_factory_method_for
@@ -56,6 +56,7 @@ class DatabaseMutexTest < Test::Unit::TestCase
56
56
  end
57
57
 
58
58
  private def lock_exists?(string)
59
+ string = string.downcase
59
60
  ActiveRecord::Base.all_mutexes.map(&:OBJECT_NAME).any? {
60
61
  _1.include?(string)
61
62
  }
@@ -73,7 +74,7 @@ class DatabaseMutexTest < Test::Unit::TestCase
73
74
 
74
75
  def test_create
75
76
  mutex = Implementation.new(:name => 'Create')
76
- assert_equal 'Create', mutex.name
77
+ assert_equal 'create', mutex.name
77
78
  end
78
79
 
79
80
  def test_lock
@@ -284,11 +285,11 @@ class DatabaseMutexTest < Test::Unit::TestCase
284
285
 
285
286
  def test_internal_name
286
287
  mutex = Implementation.new(:name => (250..255).map(&:chr) * '')
287
- assert_equal '$3i3xQvUrNPGyH6kaIOkiPw', mutex.send(:internal_name)
288
+ assert_equal '$3i3xqvurnpgyh6kaiokipw', mutex.send(:internal_name)
288
289
  end
289
290
 
290
291
  def test_counter_name
291
292
  mutex = Implementation.new(:name => (250..255).map(&:chr) * '')
292
- assert_equal '@$3i3xQvUrNPGyH6kaIOkiPw', mutex.send(:counter)
293
+ assert_equal '@$3i3xqvurnpgyh6kaiokipw', mutex.send(:counter)
293
294
  end
294
295
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_mutex
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank