Class: Tie
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Tie
- Defined in:
- app/models/tie.rb
Overview
Authorization
When an Actor establishes a Tie with other, she is granting a set of Permissions to them (posting to her wall, reading her posts, etc..) The set of Permissions granted are associated with the Relation of the Tie.
Scopes
There are several scopes defined:
- sent_by(actor)
-
ties whose sender is actor
- received_by(actor)
-
ties whose receiver is actor
- sent_or_received_by(actor)
-
the union of the former
- related_by(relation)
-
ties with this relation. Accepts relation, relation_name, integer, array
Instance Method Summary collapse
-
#bidirectional? ⇒ Boolean
This Tie is positive and positive replied.
- #positive? ⇒ Boolean
- #positive_replied? ⇒ Boolean
- #receiver_subject ⇒ Object
- #relation_belongs_to_sender? ⇒ Boolean
- #relation_name ⇒ Object
- #sender_subject ⇒ Object
-
#set_follow_action ⇒ Object
after_create callback.
-
#unset_follow_action ⇒ Object
after_remove callback.
Instance Method Details
#bidirectional? ⇒ Boolean
This Tie is positive and positive replied
101 102 103 |
# File 'app/models/tie.rb', line 101 def bidirectional? positive? && positive_replied? end |
#positive? ⇒ Boolean
91 92 93 |
# File 'app/models/tie.rb', line 91 def positive? relation.positive? end |
#positive_replied? ⇒ Boolean
96 97 98 |
# File 'app/models/tie.rb', line 96 def positive_replied? contact.positive_replied? end |
#receiver_subject ⇒ Object
86 87 88 |
# File 'app/models/tie.rb', line 86 def receiver_subject receiver.subject end |
#relation_belongs_to_sender? ⇒ Boolean
140 141 142 143 |
# File 'app/models/tie.rb', line 140 def relation_belongs_to_sender? relation.is_a?(Relation::Single) || contact.sender_id == relation.actor_id end |
#relation_name ⇒ Object
78 79 80 |
# File 'app/models/tie.rb', line 78 def relation_name relation.try(:name) end |
#sender_subject ⇒ Object
82 83 84 |
# File 'app/models/tie.rb', line 82 def sender_subject sender.subject end |
#set_follow_action ⇒ Object
after_create callback
Create the Actor‘s follower_count
108 109 110 111 112 113 114 115 116 117 |
# File 'app/models/tie.rb', line 108 def set_follow_action return if contact.reflexive? || !relation..include?(Permission.follow.first) action = sender.action_to!(receiver) return if action.follow? action.update_attribute(:follow, true) end |
#unset_follow_action ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'app/models/tie.rb', line 124 def unset_follow_action return if contact.reflexive? || !relation..include?(Permission.follow.first) # Because we allow several ties from the same sender to the same receiver, # we check the receiver does not still have a follower tie from this sender return if Tie.sent_by(sender). received_by(receiver). ('follow', nil). present? action = sender.action_to!(receiver) action.update_attribute(:follow, false) end |