Skip to content

Commit

Permalink
Merge pull request #169 from casperisfine/ruby-2.7
Browse files Browse the repository at this point in the history
Test against ruby 2.7 and fix warnings
  • Loading branch information
rafaelfranca committed Aug 19, 2020
2 parents 27abd8b + 17a7d35 commit c8b6764
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -15,6 +15,7 @@ rvm:
- 2.4
- 2.5
- 2.6
- 2.7
- ruby-head
- jruby-18mode
- jruby-19mode
Expand Down
24 changes: 21 additions & 3 deletions lib/redis/namespace.rb
Expand Up @@ -68,7 +68,8 @@ class Namespace
"decrby" => [ :first ],
"del" => [ :all ],
"dump" => [ :first ],
"exists" => [ :first ],
"exists" => [ :all ],
"exists?" => [ :all ],
"expire" => [ :first ],
"expireat" => [ :first ],
"eval" => [ :eval_style ],
Expand Down Expand Up @@ -324,6 +325,7 @@ def exec
def eval(*args)
call_with_namespace(:eval, *args)
end
ruby2_keywords(:eval) if respond_to?(:ruby2_keywords, true)

ADMINISTRATIVE_COMMANDS.keys.each do |command|
define_method(command) do |*args, &block|
Expand All @@ -339,6 +341,7 @@ def eval(*args)
end
call_with_namespace(command, *args, &block)
end
ruby2_keywords(command) if respond_to?(:ruby2_keywords, true)
end

COMMANDS.keys.each do |command|
Expand All @@ -348,6 +351,7 @@ def eval(*args)
define_method(command) do |*args, &block|
call_with_namespace(command, *args, &block)
end
ruby2_keywords(command) if respond_to?(:ruby2_keywords, true)
end

def method_missing(command, *args, &block)
Expand All @@ -370,6 +374,7 @@ def method_missing(command, *args, &block)
super
end
end
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)

def inspect
"<#{self.class.name} v#{VERSION} with client v#{Redis::VERSION} "\
Expand Down Expand Up @@ -405,6 +410,7 @@ def call_with_namespace(command, *args, &block)
case before
when :first
args[0] = add_namespace(args[0]) if args[0]
args[-1] = ruby2_keywords_hash(args[-1]) if args[-1].is_a?(Hash)
when :all
args = add_namespace(args)
when :exclude_first
Expand All @@ -417,7 +423,7 @@ def call_with_namespace(command, *args, &block)
args.push(last) if last
when :exclude_options
if args.last.is_a?(Hash)
last = args.pop
last = ruby2_keywords_hash(args.pop)
args = add_namespace(args)
args.push(last)
else
Expand All @@ -437,6 +443,7 @@ def call_with_namespace(command, *args, &block)
args[1][:get].each_index do |i|
args[1][:get][i] = add_namespace(args[1][:get][i]) unless args[1][:get][i] == "#"
end
args[1] = ruby2_keywords_hash(args[1])
end
when :eval_style
# redis.eval() and evalsha() can either take the form:
Expand All @@ -457,7 +464,7 @@ def call_with_namespace(command, *args, &block)
when :scan_style
options = (args.last.kind_of?(Hash) ? args.pop : {})
options[:match] = add_namespace(options.fetch(:match, '*'))
args << options
args << ruby2_keywords_hash(options)

if block
original_block = block
Expand All @@ -483,9 +490,20 @@ def call_with_namespace(command, *args, &block)

result
end
ruby2_keywords(:call_with_namespace) if respond_to?(:ruby2_keywords, true)

private

if Hash.respond_to?(:ruby2_keywords_hash)
def ruby2_keywords_hash(kwargs)
Hash.ruby2_keywords_hash(kwargs)
end
else
def ruby2_keywords_hash(kwargs)
kwargs
end
end

# Avoid modifying the caller's (pass-by-reference) arguments.
def clone_args(arg)
if arg.is_a?(Array)
Expand Down
2 changes: 1 addition & 1 deletion redis-namespace.gemspec
Expand Up @@ -28,7 +28,7 @@ Gem::Specification.new do |s|

s.add_dependency "redis", ">= 3.0.4"

s.add_development_dependency "rake", "~> 10.1"
s.add_development_dependency "rake"
s.add_development_dependency "rspec", "~> 3.7"
s.add_development_dependency "rspec-its"

Expand Down
4 changes: 2 additions & 2 deletions spec/redis_spec.rb
Expand Up @@ -140,7 +140,7 @@

it 'should be able to use a namespace with setbit' do
@namespaced.setbit('virgin_key', 1, 1)
expect(@namespaced.exists('virgin_key')).to be true
expect(@namespaced.exists?('virgin_key')).to be true
expect(@namespaced.get('virgin_key')).to eq(@namespaced.getrange('virgin_key',0,-1))
end

Expand Down Expand Up @@ -239,7 +239,7 @@
@namespaced.zadd('sort2', 2, 2)
@namespaced.zadd('sort2', 3, 3)
@namespaced.zadd('sort2', 4, 4)
@namespaced.zunionstore('union', ['sort1', 'sort2'], :weights => [2, 1])
@namespaced.zunionstore('union', ['sort1', 'sort2'], weights: [2, 1])
expect(@namespaced.zrevrange('union', 0, -1)).to eq(%w( 2 4 3 1 ))
end

Expand Down
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -12,6 +12,10 @@
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
require 'redis/namespace'

if Redis.respond_to?(:exists_returns_integer=)
Redis.exists_returns_integer = true
end

module Helper
def capture_stderr(io = nil)
require 'stringio'
Expand Down

0 comments on commit c8b6764

Please sign in to comment.