Skip to content

Commit 21bd929

Browse files
authored
Merge pull request #88 from ClosureTree/zeitwrek
feat: use zeitwerk loader instead of ActiveSupport::Autoload
2 parents 01ddea4 + b5082fd commit 21bd929

File tree

5 files changed

+14
-16
lines changed

5 files changed

+14
-16
lines changed

lib/with_advisory_lock.rb

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
require 'with_advisory_lock/version'
22
require 'active_support'
3-
require_relative 'with_advisory_lock/failed_to_acquire_lock'
3+
require 'zeitwerk'
44

5-
module WithAdvisoryLock
6-
extend ActiveSupport::Autoload
5+
loader = Zeitwerk::Loader.for_gem
6+
loader.inflector.inflect(
7+
'mysql' => 'MySQL',
8+
'postgresql' => 'PostgreSQL',
9+
)
10+
loader.setup
711

8-
autoload :Concern
9-
autoload :Base
10-
autoload :DatabaseAdapterSupport
11-
autoload :Flock
12-
autoload :MySQL, 'with_advisory_lock/mysql'
13-
autoload :PostgreSQL, 'with_advisory_lock/postgresql'
12+
module WithAdvisoryLock
1413
end
1514

1615
ActiveSupport.on_load :active_record do

lib/with_advisory_lock/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def stable_hashcode(input)
7979
else
8080
# Ruby MRI's String#hash is randomly seeded as of Ruby 1.9 so
8181
# make sure we use a deterministic hash.
82-
Zlib.crc32(input.to_s)
82+
Zlib.crc32(input.to_s, 0)
8383
end
8484
end
8585

lib/with_advisory_lock/concern.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# frozen_string_literal: true
22

3-
require 'active_support/concern'
4-
53
module WithAdvisoryLock
64
module Concern
75
extend ActiveSupport::Concern
@@ -15,9 +13,7 @@ def with_advisory_lock(lock_name, options = {}, &block)
1513

1614
def with_advisory_lock!(lock_name, options = {}, &block)
1715
result = with_advisory_lock_result(lock_name, options, &block)
18-
unless result.lock_was_acquired?
19-
raise WithAdvisoryLock::FailedToAcquireLock, lock_name
20-
end
16+
raise WithAdvisoryLock::FailedToAcquireLock, lock_name unless result.lock_was_acquired?
2117

2218
result.result
2319
end
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
# frozen_string_literal: true
2+
13
module WithAdvisoryLock
24
class FailedToAcquireLock < StandardError
35
def initialize(lock_name)
46
super("Failed to acquire lock #{lock_name}")
57
end
68
end
7-
end
9+
end

with_advisory_lock.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
2525
spec.metadata['changelog_uri'] = 'https://github.com/ClosureTree/with_advisory_lock/blob/master/CHANGELOG.md'
2626

2727
spec.add_runtime_dependency 'activerecord', '>= 6.1'
28+
spec.add_runtime_dependency 'zeitwerk', '>= 2.6'
2829

2930
spec.add_development_dependency 'appraisal'
3031
spec.add_development_dependency 'maxitest'

0 commit comments

Comments
 (0)