friendis 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/friendis/friendable.rb +22 -23
- data/lib/friendis/version.rb +1 -1
- data/spec/lib/friendable_spec.rb +24 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 356a53acac2adc1dd9b0c89cedb8b96c3da62591
|
4
|
+
data.tar.gz: 134819bde4df5bde734e1286e6da35b4f3616615
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1039c86f859140f530a4902b3441bc49306b528f9804d7abdda5dbf2f5ad2c191706dd0433d793b4c4eaaf365461266ca90761c3d94a7d153266963bf9ac61b7
|
7
|
+
data.tar.gz: dd91a510ce170f278663e858d841313540464f907a8cb6de16bfc0524e97dbb2a60389df65e9be61d4582ef354f6bf058fa4d3f30c431f68e4784449c816eb1d
|
data/lib/friendis/friendable.rb
CHANGED
@@ -15,7 +15,7 @@ module Friendis
|
|
15
15
|
end
|
16
16
|
|
17
17
|
module ClassMethods
|
18
|
-
|
18
|
+
|
19
19
|
# Mark the list of fields to track in redis for fast access.
|
20
20
|
def friend_this(options = {})
|
21
21
|
configuration = {
|
@@ -37,9 +37,9 @@ module Friendis
|
|
37
37
|
|
38
38
|
end
|
39
39
|
|
40
|
-
module InstanceMethods
|
40
|
+
module InstanceMethods
|
41
|
+
|
41
42
|
|
42
|
-
|
43
43
|
|
44
44
|
def get_friendis_meta(uuid = nil)
|
45
45
|
Friendis.redis.hgetall friendis_meta_key(uuid)
|
@@ -53,31 +53,26 @@ module Friendis
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def approve_friend_request(friend)
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
Friendis.redis.
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
Friendis.redis.sadd friend.friendis_my_friends_key, self.id.to_s
|
64
|
-
end
|
65
|
-
return true
|
56
|
+
return false unless has_friend_request_from?(friend)
|
57
|
+
|
58
|
+
Friendis.redis.multi do
|
59
|
+
Friendis.redis.srem friend.friendis_outgoing_friend_requests_key, self.id.to_s
|
60
|
+
Friendis.redis.srem friendis_incoming_friend_requests_key, friend.id.to_s
|
61
|
+
Friendis.redis.sadd friendis_my_friends_key, friend.id.to_s
|
62
|
+
Friendis.redis.sadd friend.friendis_my_friends_key, self.id.to_s
|
66
63
|
end
|
64
|
+
true
|
67
65
|
end
|
68
66
|
|
69
67
|
def ignore_friend_request(friend)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
Friendis.redis.multi do
|
77
|
-
Friendis.redis.srem friendis_incoming_friend_requests_key, friend.id.to_s
|
78
|
-
end
|
79
|
-
return true
|
68
|
+
return false unless has_friend_request_from?(friend)
|
69
|
+
|
70
|
+
# Ignoring a friend request, leaves the request in the requester queue, but removes
|
71
|
+
# it from the pending requests list of the recipient.
|
72
|
+
Friendis.redis.multi do
|
73
|
+
Friendis.redis.srem friendis_incoming_friend_requests_key, friend.id.to_s
|
80
74
|
end
|
75
|
+
true
|
81
76
|
end
|
82
77
|
|
83
78
|
def unfriend(friend)
|
@@ -91,6 +86,10 @@ module Friendis
|
|
91
86
|
Friendis.redis.smembers(friendis_my_friends_key).collect {|friend_id| get_friendis_meta(friend_id)}
|
92
87
|
end
|
93
88
|
|
89
|
+
def has_friend_request_from?(friend)
|
90
|
+
Friendis.redis.sismember friendis_incoming_friend_requests_key, friend.id.to_s
|
91
|
+
end
|
92
|
+
|
94
93
|
def is_friends_with?(friend)
|
95
94
|
Friendis.redis.sismember friendis_my_friends_key, friend.id.to_s
|
96
95
|
end
|
data/lib/friendis/version.rb
CHANGED
data/spec/lib/friendable_spec.rb
CHANGED
@@ -117,4 +117,28 @@ describe Friendis::Friendable do
|
|
117
117
|
|
118
118
|
end
|
119
119
|
|
120
|
+
describe "#has_friend_request_from?" do
|
121
|
+
before(:each) do
|
122
|
+
@user1 = User.new(1)
|
123
|
+
@user2 = User.new(2)
|
124
|
+
|
125
|
+
@user1.clear_friendis_data
|
126
|
+
@user2.clear_friendis_data
|
127
|
+
|
128
|
+
@user1.save
|
129
|
+
@user2.save
|
130
|
+
|
131
|
+
@user1.send_friend_request(@user2)
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should return true if a user has request from other" do
|
135
|
+
@user2.has_friend_request_from?(@user1).should be_truthy
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should return false if a user has no request from other" do
|
139
|
+
@user1.has_friend_request_from?(@user2).should be_falsy
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
120
144
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: friendis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elad Meidar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
112
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.2.
|
113
|
+
rubygems_version: 2.2.2
|
114
114
|
signing_key:
|
115
115
|
specification_version: 4
|
116
116
|
summary: Friendis implements friendship relationship between objects on Redis
|
@@ -120,3 +120,4 @@ test_files:
|
|
120
120
|
- spec/lib/friendable_spec.rb
|
121
121
|
- spec/models/user.rb
|
122
122
|
- spec/spec_helper.rb
|
123
|
+
has_rdoc:
|