Class: Tie

Inherits:
ActiveRecord::Base
  • Object
show all
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

Instance Method Details

#bidirectional?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'app/models/tie.rb', line 99

def bidirectional?
  positive? && positive_replied?
end

#positive?Boolean

The Tie is positive if its Relation is

Returns:

  • (Boolean)


89
90
91
# File 'app/models/tie.rb', line 89

def positive?
  relation.positive?
end

#positive_replied?Boolean

Does this Tie have positive ties in the other way?

Returns:

  • (Boolean)


94
95
96
# File 'app/models/tie.rb', line 94

def positive_replied?
  contact.positive_replied?
end

#receiver_subjectObject



84
85
86
# File 'app/models/tie.rb', line 84

def receiver_subject
  receiver.subject
end

#relation_nameObject



76
77
78
# File 'app/models/tie.rb', line 76

def relation_name
  relation.try(:name)
end

#sender_subjectObject



80
81
82
# File 'app/models/tie.rb', line 80

def sender_subject
  sender.subject
end

#set_follow_actionObject

after_create callback

Create the Actor‘s follower_count



106
107
108
109
110
111
112
113
114
115
# File 'app/models/tie.rb', line 106

def set_follow_action
  return if contact.reflexive? ||
            !relation.permissions.include?(Permission.follow.first)

  action = sender.action_to!(receiver)

  return if action.follow?

  action.update_attribute(:follow, true)
end

#unset_follow_actionObject

after_remove callback

Decrement the Actor‘s follower_count

This method needs to be public to be call from Contact‘s after_remove callback



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'app/models/tie.rb', line 122

def unset_follow_action
  return if contact.reflexive? ||
            !relation.permissions.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).
                with_permissions('follow', nil).
                present?

  action = sender.action_to!(receiver)

  action.update_attribute(:follow, false)
end