upvote 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/upvote.rb +19 -4
- data/lib/upvote/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f3d34cd07fcc6b8eddcf29459318b08796c29ae
|
4
|
+
data.tar.gz: 761b7c4cceae2749049e51d7d7b62aade7234a76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c7d097806ea8b6a55e3adfe1b52b0dbd0ce3d70b42d892e7b72bc6926cf184ce4cd3796864c5c5cbdb7dc49c8175e1a7edcaa56a2647d9b8f6488fe2895cd58
|
7
|
+
data.tar.gz: d09180d3f098ab6ecba05570c003b2b90ecab4fd72915a0430a494094b605a3ff6f6f2dc49ecc045b3fbcf3a60268cd2df03f6e51ba401da295ed5d2236fed6a
|
data/lib/upvote.rb
CHANGED
@@ -18,6 +18,15 @@ module Upvote
|
|
18
18
|
execute ? redis.multi { creation.call } : creation
|
19
19
|
end
|
20
20
|
|
21
|
+
def remove(subject, target, execute: true)
|
22
|
+
removal = ->() {
|
23
|
+
redis.zrem set_key(subject), key(target)
|
24
|
+
redis.zrem set_key(target), key(subject)
|
25
|
+
}
|
26
|
+
|
27
|
+
execute ? redis.multi { removal.call } : removal
|
28
|
+
end
|
29
|
+
|
21
30
|
def exist?(subject, target)
|
22
31
|
redis.zscore(set_key(target), key(subject)).present?
|
23
32
|
end
|
@@ -40,6 +49,16 @@ module Upvote
|
|
40
49
|
end
|
41
50
|
end
|
42
51
|
|
52
|
+
def multi_remove(removals)
|
53
|
+
redis.multi do
|
54
|
+
removals.each do |subject, *targets|
|
55
|
+
targets.each do |target|
|
56
|
+
remove(subject, target, execute: false).call
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
43
62
|
def multi_count(entities)
|
44
63
|
redis.multi { entities.each &method(:count) }
|
45
64
|
end
|
@@ -62,8 +81,4 @@ module Upvote
|
|
62
81
|
'${type}#${id}' % { type: klass.to_s.underscore, id: entity.send(method) }
|
63
82
|
end
|
64
83
|
|
65
|
-
def transaction
|
66
|
-
redis.multi { yield }
|
67
|
-
end
|
68
|
-
|
69
84
|
end
|
data/lib/upvote/version.rb
CHANGED