Skip to content

Commit

Permalink
Merge pull request #39 from BIAINC/ruby-1.9-compat
Browse files Browse the repository at this point in the history
Ruby 1.9 compatibility
  • Loading branch information
leandromoreira committed May 20, 2016
2 parents b8a3f26 + 22947ef commit e839b52
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PATH
remote: .
specs:
redlock (0.1.7)
redis (~> 3, >= 3.3.0)
redis (~> 3, >= 3.0.0)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -49,7 +49,7 @@ DEPENDENCIES
coveralls (~> 0.8.13)
rake (~> 11.1, >= 11.1.2)
redlock!
rspec (~> 3.4, >= 3.4.0)
rspec (~> 3, >= 3.0.0)

BUNDLED WITH
1.12.3
7 changes: 4 additions & 3 deletions lib/redlock/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def initialize(servers = DEFAULT_REDIS_URLS, options = {})
# +extend+: A lock ("lock_info") to extend.
# +block+:: an optional block to be executed; after its execution, the lock (if successfully
# acquired) is automatically unlocked.
def lock(resource, ttl, extend: nil, &block)
def lock(resource, ttl, options={}, &block)
extend = options[:extend] || nil
lock_info = try_lock_instances(resource, ttl, extend)

if block_given?
Expand Down Expand Up @@ -94,10 +95,10 @@ def unlock(lock_info)
# Locks a resource, executing the received block only after successfully acquiring the lock,
# and returning its return value as a result.
# See Redlock::Client#lock for parameters.
def lock!(*args, **keyword_args)
def lock!(*args)
fail 'No block passed' unless block_given?

lock(*args, **keyword_args) do |lock_info|
lock(*args) do |lock_info|
raise LockError, 'failed to acquire lock' unless lock_info
return yield
end
Expand Down
4 changes: 2 additions & 2 deletions redlock.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_dependency 'redis', '~> 3', '>= 3.3.0'
spec.add_dependency 'redis', '~> 3', '>= 3.0.0'

spec.add_development_dependency 'bundler', '~> 1.12', '>= 1.12.3'
spec.add_development_dependency "coveralls", "~> 0.8.13"
spec.add_development_dependency 'rake', '~> 11.1', '>= 11.1.2'
spec.add_development_dependency 'rspec', '~> 3.4', '>= 3.4.0'
spec.add_development_dependency 'rspec', '~> 3', '>= 3.0.0'
end
5 changes: 5 additions & 0 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@
lock_manager.lock!(resource_key, ttl) { fail } rescue nil
expect(resource_key).to be_lockable(lock_manager, ttl)
end

it 'passes the extension parameter' do
my_lock_info = lock_manager.lock(resource_key, ttl)
expect{ lock_manager.lock!(resource_key, ttl, extend: my_lock_info){} }.to_not raise_error
end
end

context 'when lock is not available' do
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Coveralls.wear!
require 'redlock'

LOCK_INFO_KEYS = %i{validity resource value}
LOCK_INFO_KEYS = [:validity, :resource, :value]

RSpec::Matchers.define :be_lock_info_for do |resource|
def correct_type?(actual)
Expand Down

0 comments on commit e839b52

Please sign in to comment.