Class: Circle::Friendship
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Circle::Friendship
- Defined in:
- lib/circle/models/friendship.rb
Constant Summary collapse
- STATUS_ALREADY_FRIENDS =
1
- STATUS_ALREADY_REQUESTED =
2
- STATUS_FRIEND_IS_YOURSELF =
3
- STATUS_FRIENDSHIP_ACCEPTED =
4
- STATUS_FRIENDSHIP_DENIED =
5
- STATUS_REQUESTED =
6
- STATUS_CANNOT_SEND =
7
- STATUS_CANNOT_ACCEPT =
8
- STATUS_NOT_FOUND =
9
- STATUS_BLOCKED =
10
- STATUS_UNBLOCKED =
11
- FRIENDSHIP_ACCEPTED =
"accepted"
- FRIENDSHIP_PENDING =
"pending"
- FRIENDSHIP_REQUESTED =
"requested"
- FRIENDSHIP_DENIED =
"denied"
- FRIENDSHIP_BLOCKED =
"blocked"
Instance Method Summary collapse
- #accept! ⇒ Object
- #accepted? ⇒ Boolean
- #block!(add_to_block_list = false) ⇒ Object
- #blocked? ⇒ Boolean
- #denied? ⇒ Boolean
- #deny! ⇒ Object
- #pending? ⇒ Boolean
- #requested? ⇒ Boolean
Instance Method Details
#accept! ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/circle/models/friendship.rb', line 58 def accept! unless accepted? self.transaction do User.increment_counter(:friends_count, user_id) update_attribute(:status, FRIENDSHIP_ACCEPTED) update_attribute(:accepted_at, Time.now) end end end |
#accepted? ⇒ Boolean
42 43 44 |
# File 'lib/circle/models/friendship.rb', line 42 def accepted? status == FRIENDSHIP_ACCEPTED end |
#block!(add_to_block_list = false) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/circle/models/friendship.rb', line 75 def block!(add_to_block_list = false) self.transaction do update_attribute(:status, Circle::Friendship::FRIENDSHIP_BLOCKED) update_attribute(:blocked_at, Time.now) self.user.users_blocked.create(blocked_user_id: self.friend.id) if add_to_block_list end end |
#blocked? ⇒ Boolean
54 55 56 |
# File 'lib/circle/models/friendship.rb', line 54 def blocked? status == FRIENDSHIP_BLOCKED end |
#denied? ⇒ Boolean
50 51 52 |
# File 'lib/circle/models/friendship.rb', line 50 def denied? status == FRIENDSHIP_DENIED end |
#deny! ⇒ Object
68 69 70 71 72 73 |
# File 'lib/circle/models/friendship.rb', line 68 def deny! self.transaction do update_attribute(:status, Circle::Friendship::FRIENDSHIP_DENIED) update_attribute(:denied_at, Time.now) end end |
#pending? ⇒ Boolean
38 39 40 |
# File 'lib/circle/models/friendship.rb', line 38 def pending? status == FRIENDSHIP_PENDING end |
#requested? ⇒ Boolean
46 47 48 |
# File 'lib/circle/models/friendship.rb', line 46 def requested? status == FRIENDSHIP_REQUESTED end |