Module: DataMapper::Is::Friendly::InstanceMethods
- Defined in:
- lib/dm-is-friendly/is/friendly.rb
Instance Method Summary collapse
-
#confirm_friendship_with(friend) ⇒ self
Accepts a user and updates an existing friendship to be accepted.
-
#end_friendship_with(friend) ⇒ true, false
Accepts a user and deletes a friendship between both users.
-
#friends ⇒ DataMapper::Collection
returns all of the friends this person has that are accepted.
-
#friendship_requested?(friend) ⇒ true, false
see if there is a pending friendship request from this person to another.
-
#friendship_requests(friend = nil, include_accepted = false) ⇒ DataMapper::Collection
returns all the people I have requested frienship from.
-
#friendship_to_accept?(friend) ⇒ true, false
see if user has a friend request to accept from this person.
-
#friendships_to_accept(friend = nil, include_accepted = false) ⇒ DataMapper::Collection
returns all the people that have requested my friendship.
-
#is_friends_with?(friend) ⇒ true, false
Accepts a user object and returns true if both users are friends and the friendship has been accepted.
-
#request_friendship(friend) ⇒ Object
request friendship from “friend”.
Instance Method Details
#confirm_friendship_with(friend) ⇒ self
Accepts a user and updates an existing friendship to be accepted.
126 127 128 129 130 131 |
# File 'lib/dm-is-friendly/is/friendly.rb', line 126 def confirm_friendship_with(friend) self.friendship(friend,{:accepted_at => nil}).update({:accepted_at => Time.now}) # reload so old relationship won't be lingering in the IdentityMap friend.reload self.reload end |
#end_friendship_with(friend) ⇒ true, false
Accepts a user and deletes a friendship between both users.
136 137 138 |
# File 'lib/dm-is-friendly/is/friendly.rb', line 136 def end_friendship_with(friend) self.friendship(friend).destroy if self.is_friends_with?(friend) end |
#friends ⇒ DataMapper::Collection
returns all of the friends this person has that are accepted
62 63 64 |
# File 'lib/dm-is-friendly/is/friendly.rb', line 62 def friends friendship_requests(nil,true) | friendships_to_accept(nil,true) end |
#friendship_requested?(friend) ⇒ true, false
see if there is a pending friendship request from this person to another
95 96 97 |
# File 'lib/dm-is-friendly/is/friendly.rb', line 95 def friendship_requested?(friend) !friendship_requests(friend).empty? end |
#friendship_requests(friend = nil, include_accepted = false) ⇒ DataMapper::Collection
returns all the people I have requested frienship from
70 71 72 73 74 75 76 77 |
# File 'lib/dm-is-friendly/is/friendly.rb', line 70 def friendship_requests(friend = nil, include_accepted = false) conditions = {} friend_acceptance_condition(conditions, include_accepted) friend_scope_condition(conditions, friend) conditions[friendly_config.friendship_foreign_key] = self.id friendly_config.friendship_class.all(conditions).friend end |
#friendship_to_accept?(friend) ⇒ true, false
see if user has a friend request to accept from this person
102 103 104 105 |
# File 'lib/dm-is-friendly/is/friendly.rb', line 102 def friendship_to_accept?(friend) return false unless friendly_config.require_acceptance? !friendships_to_accept(friend).empty? end |
#friendships_to_accept(friend = nil, include_accepted = false) ⇒ DataMapper::Collection
returns all the people that have requested my friendship
83 84 85 86 87 88 89 90 |
# File 'lib/dm-is-friendly/is/friendly.rb', line 83 def friendships_to_accept(friend = nil, include_accepted = false) conditions = {} friend_acceptance_condition(conditions, include_accepted) friend_scope_condition(conditions, friend, true) conditions[:friend_id] = self.id friendly_config.friendship_class.all(conditions).send(friendly_config.reference_model_name.downcase) end |
#is_friends_with?(friend) ⇒ true, false
Accepts a user object and returns true if both users are friends and the friendship has been accepted.
111 112 113 |
# File 'lib/dm-is-friendly/is/friendly.rb', line 111 def is_friends_with?(friend) !self.friendship(friend).nil? end |
#request_friendship(friend) ⇒ Object
request friendship from “friend”
118 119 120 121 |
# File 'lib/dm-is-friendly/is/friendly.rb', line 118 def request_friendship(friend) return false if friendship(friend) self.friendships.create(:friend => friend) end |