upvote 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/upvote.rb +19 -4
  3. data/lib/upvote/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2841bd9f9f689699df386e32a205c6446b678d19
4
- data.tar.gz: 1ed2f0441b4cf7d2927025a22b183be9c72bab25
3
+ metadata.gz: 9f3d34cd07fcc6b8eddcf29459318b08796c29ae
4
+ data.tar.gz: 761b7c4cceae2749049e51d7d7b62aade7234a76
5
5
  SHA512:
6
- metadata.gz: 5859477d84008de83b4d4a5b225590d8f13a7c59d6672a7c549078a5a633af04990a63db552cdba612f211fe5d2e99342158b24cc23aa6b45827cfdc460b8bb1
7
- data.tar.gz: b5cd266a7679fcd9eeae5b8c1f9b2093062de67c995ba6a5a450a631f3184e8bf64a53476e4f779ae1a9d16e82ca6c8ddb868bf55b43adadcb7a093eb7aa18c5
6
+ metadata.gz: 6c7d097806ea8b6a55e3adfe1b52b0dbd0ce3d70b42d892e7b72bc6926cf184ce4cd3796864c5c5cbdb7dc49c8175e1a7edcaa56a2647d9b8f6488fe2895cd58
7
+ data.tar.gz: d09180d3f098ab6ecba05570c003b2b90ecab4fd72915a0430a494094b605a3ff6f6f2dc49ecc045b3fbcf3a60268cd2df03f6e51ba401da295ed5d2236fed6a
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Upvote
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upvote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Rodrigues