Module: Friendis::Friendable::InstanceMethods
- Defined in:
- lib/friendis/friendable.rb
Instance Method Summary collapse
- #_update_friendis_meta_data ⇒ Object
- #approve_friend_request(friend) ⇒ Object
- #clear_friendis_data ⇒ Object
- #friendis_incoming_friend_requests_key ⇒ Object
- #friendis_meta_key(uuid = nil) ⇒ Object
- #friendis_my_friends_key ⇒ Object
- #friendis_outgoing_friend_requests_key ⇒ Object
- #friends ⇒ Object
- #get_friendis_meta(uuid = nil) ⇒ Object
- #ignore_friend_request(friend) ⇒ Object
- #is_friends_with?(friend) ⇒ Boolean
- #pending_friend_requests ⇒ Object
- #send_friend_request(friend) ⇒ Object
- #sent_friend_requests ⇒ Object
- #unfriend(friend) ⇒ Object
Instance Method Details
#_update_friendis_meta_data ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/friendis/friendable.rb', line 112 def Friendis.redis.multi do attr_hash = {} self.class.friendis_fields.each do |field| attr_hash[field] = self.send(field) end Friendis.redis.hmset , *attr_hash.to_a end true end |
#approve_friend_request(friend) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/friendis/friendable.rb', line 55 def approve_friend_request(friend) if !(Friendis.redis.sismember(friendis_incoming_friend_requests_key, friend.id.to_s)) return false else Friendis.redis.multi do Friendis.redis.srem friend.friendis_outgoing_friend_requests_key, self.id.to_s Friendis.redis.srem friendis_incoming_friend_requests_key, friend.id.to_s Friendis.redis.sadd friendis_my_friends_key, friend.id.to_s Friendis.redis.sadd friend.friendis_my_friends_key, self.id.to_s end return true end end |
#clear_friendis_data ⇒ Object
106 107 108 109 110 |
# File 'lib/friendis/friendable.rb', line 106 def clear_friendis_data [, friendis_my_friends_key, friendis_incoming_friend_requests_key, friendis_outgoing_friend_requests_key].each do |friendis_key| Friendis.redis.del friendis_key end end |
#friendis_incoming_friend_requests_key ⇒ Object
132 133 134 |
# File 'lib/friendis/friendable.rb', line 132 def friendis_incoming_friend_requests_key "#{self.class.name.downcase}:#{self.id}:friend_requests" end |
#friendis_meta_key(uuid = nil) ⇒ Object
124 125 126 |
# File 'lib/friendis/friendable.rb', line 124 def (uuid = nil) "#{self.class.name.downcase}:#{uuid || self.id}:friendis_meta" end |
#friendis_my_friends_key ⇒ Object
128 129 130 |
# File 'lib/friendis/friendable.rb', line 128 def friendis_my_friends_key "#{self.class.name.downcase}:#{self.id}:friends" end |
#friendis_outgoing_friend_requests_key ⇒ Object
136 137 138 |
# File 'lib/friendis/friendable.rb', line 136 def friendis_outgoing_friend_requests_key "#{self.class.name.downcase}:#{self.id}:requested_friendship" end |
#friends ⇒ Object
90 91 92 |
# File 'lib/friendis/friendable.rb', line 90 def friends Friendis.redis.smembers(friendis_my_friends_key).collect {|friend_id| (friend_id)} end |
#get_friendis_meta(uuid = nil) ⇒ Object
44 45 46 |
# File 'lib/friendis/friendable.rb', line 44 def (uuid = nil) Friendis.redis.hgetall (uuid) end |
#ignore_friend_request(friend) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/friendis/friendable.rb', line 69 def ignore_friend_request(friend) if !(Friendis.redis.sismember(friendis_incoming_friend_requests_key, friend.id.to_s)) return false else # Ignoring a friend request, leaves the request in the requester queue, but removes # it from the pending requests list of the recipient. Friendis.redis.multi do Friendis.redis.srem friendis_incoming_friend_requests_key, friend.id.to_s end return true end end |
#is_friends_with?(friend) ⇒ Boolean
94 95 96 |
# File 'lib/friendis/friendable.rb', line 94 def is_friends_with?(friend) Friendis.redis.sismember friendis_my_friends_key, friend.id.to_s end |
#pending_friend_requests ⇒ Object
98 99 100 |
# File 'lib/friendis/friendable.rb', line 98 def pending_friend_requests Friendis.redis.smembers(friendis_incoming_friend_requests_key).collect {|friend_id| (friend_id)} end |
#send_friend_request(friend) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/friendis/friendable.rb', line 48 def send_friend_request(friend) Friendis.redis.multi do Friendis.redis.sadd friendis_outgoing_friend_requests_key, friend.id.to_s Friendis.redis.sadd friend.friendis_incoming_friend_requests_key, self.id.to_s end end |
#sent_friend_requests ⇒ Object
102 103 104 |
# File 'lib/friendis/friendable.rb', line 102 def sent_friend_requests Friendis.redis.smembers(friendis_outgoing_friend_requests_key).collect {|friend_id| (friend_id)} end |
#unfriend(friend) ⇒ Object
83 84 85 86 87 88 |
# File 'lib/friendis/friendable.rb', line 83 def unfriend(friend) Friendis.redis.multi do Friendis.redis.srem friendis_my_friends_key, friend.id Friendis.redis.srem friend.friendis_my_friends_key, self.id end end |