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
- #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
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/friendis/friendable.rb', line 98 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
92 93 94 95 96 |
# File 'lib/friendis/friendable.rb', line 92 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
118 119 120 |
# File 'lib/friendis/friendable.rb', line 118 def friendis_incoming_friend_requests_key "#{self.class.name.downcase}:#{self.id}:friend_requests" end |
#friendis_meta_key(uuid = nil) ⇒ Object
110 111 112 |
# File 'lib/friendis/friendable.rb', line 110 def (uuid = nil) "#{self.class.name.downcase}:#{uuid || self.id}:friendis_meta" end |
#friendis_my_friends_key ⇒ Object
114 115 116 |
# File 'lib/friendis/friendable.rb', line 114 def friendis_my_friends_key "#{self.class.name.downcase}:#{self.id}:friends" end |
#friendis_outgoing_friend_requests_key ⇒ Object
122 123 124 |
# File 'lib/friendis/friendable.rb', line 122 def friendis_outgoing_friend_requests_key "#{self.class.name.downcase}:#{self.id}:requested_friendship" end |
#friends ⇒ Object
76 77 78 |
# File 'lib/friendis/friendable.rb', line 76 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 |
#is_friends_with?(friend) ⇒ Boolean
80 81 82 |
# File 'lib/friendis/friendable.rb', line 80 def is_friends_with?(friend) Friendis.redis.sismember friendis_my_friends_key, friend.id.to_s end |
#pending_friend_requests ⇒ Object
84 85 86 |
# File 'lib/friendis/friendable.rb', line 84 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
88 89 90 |
# File 'lib/friendis/friendable.rb', line 88 def sent_friend_requests Friendis.redis.smembers(friendis_outgoing_friend_requests_key).collect {|friend_id| (friend_id)} end |
#unfriend(friend) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/friendis/friendable.rb', line 69 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 |