Skip to content

Commit 9be4e02

Browse files
authored
Delegate exists? to proxy for all types (#47)
* Delegate `exists?` to proxy for all types * Explicitly add exists proxy and add tests
1 parent d048de3 commit 9be4e02

File tree

14 files changed

+56
-7
lines changed

14 files changed

+56
-7
lines changed

lib/kredis/types/counter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class Kredis::Types::Counter < Kredis::Types::Proxying
2-
proxying :multi, :set, :incrby, :decrby, :get, :del
2+
proxying :multi, :set, :incrby, :decrby, :get, :del, :exists?
33

44
attr_accessor :expires_in
55

lib/kredis/types/enum.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require "active_support/core_ext/object/inclusion"
22

33
class Kredis::Types::Enum < Kredis::Types::Proxying
4-
proxying :set, :get, :del
4+
proxying :set, :get, :del, :exists?
55

66
attr_accessor :values, :default
77

lib/kredis/types/hash.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require "active_support/core_ext/hash"
22

33
class Kredis::Types::Hash < Kredis::Types::Proxying
4-
proxying :hget, :hset, :hmget, :hdel, :hgetall, :hkeys, :hvals, :del
4+
proxying :hget, :hset, :hmget, :hdel, :hgetall, :hkeys, :hvals, :del, :exists?
55

66
attr_accessor :typed
77

lib/kredis/types/list.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class Kredis::Types::List < Kredis::Types::Proxying
2-
proxying :lrange, :lrem, :lpush, :rpush
2+
proxying :lrange, :lrem, :lpush, :rpush, :exists?
33

44
attr_accessor :typed
55

lib/kredis/types/set.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class Kredis::Types::Set < Kredis::Types::Proxying
2-
proxying :smembers, :sadd, :srem, :multi, :del, :sismember, :scard, :spop
2+
proxying :smembers, :sadd, :srem, :multi, :del, :sismember, :scard, :spop, :exists?
33

44
attr_accessor :typed
55

lib/kredis/types/slots.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class Kredis::Types::Slots < Kredis::Types::Proxying
22
class NotAvailable < StandardError; end
33

4-
proxying :incr, :decr, :get, :del
4+
proxying :incr, :decr, :get, :del, :exists?
55

66
attr_accessor :available
77

lib/kredis/types/unique_list.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# You'd normally call this a set, but Redis already has another data type for that
22
class Kredis::Types::UniqueList < Kredis::Types::List
3-
proxying :multi, :ltrim
3+
proxying :multi, :ltrim, :exists?
44

55
attr_accessor :typed, :limit
66

test/types/counter_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,11 @@ class CounterTest < ActiveSupport::TestCase
6363
stub_redis_down(@counter) { @counter.increment }
6464
assert_equal 0, @counter.value
6565
end
66+
67+
test "exists?" do
68+
assert_not @counter.exists?
69+
70+
@counter.increment
71+
assert @counter.exists?
72+
end
6673
end

test/types/enum_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,11 @@ class EnumTest < ActiveSupport::TestCase
3030
@enum.reset
3131
assert @enum.one?
3232
end
33+
34+
test "exists?" do
35+
assert_not @enum.exists?
36+
37+
@enum.value = "one"
38+
assert @enum.exists?
39+
end
3340
end

test/types/hash_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,11 @@ class HashTest < ActiveSupport::TestCase
7676
@hash.remove
7777
assert_equal({}, @hash.to_h)
7878
end
79+
80+
test "exists?" do
81+
assert_not @hash.exists?
82+
83+
@hash[:key] = :value
84+
assert @hash.exists?
85+
end
7986
end

0 commit comments

Comments
 (0)