Module: Diaspora::Relayable

Included in:
Comment, Like, PollParticipation
Defined in:
lib/diaspora/relayable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(model) ⇒ Object


9
10
11
12
13
14
15
16
17
18
# File 'lib/diaspora/relayable.rb', line 9

def self.included(model)
  model.class_eval do
    validates :parent, presence: true
    validates_associated :parent
    validate :author_is_not_ignored

    delegate :public?, to: :parent
    delegate :author, :diaspora_handle, to: :parent, prefix: true
  end
end

Instance Method Details

#author_is_not_ignoredObject


26
27
28
29
30
31
32
33
# File 'lib/diaspora/relayable.rb', line 26

def author_is_not_ignored
  unless new_record? && root.present? && root.author.local? &&
    root.author.owner.ignored_people.include?(author)
    return
  end

  errors.add(:author_id, "This relayable author is ignored by the post author")
end

#parentObject

This method is abstract.

Raises:

  • (NotImplementedError)

53
54
55
# File 'lib/diaspora/relayable.rb', line 53

def parent
  raise NotImplementedError.new('you must override parent in order to enable relayable on this model')
end

#rootObject


20
21
22
23
24
# File 'lib/diaspora/relayable.rb', line 20

def root
  @root ||= parent
  @root = @root.parent while @root.is_a?(Relayable)
  @root
end

#sender_for_dispatchObject


48
49
50
# File 'lib/diaspora/relayable.rb', line 48

def sender_for_dispatch
  root.author.owner if root.author.local?
end

#subscribersArray<Person>

Returns:


36
37
38
39
40
41
42
43
44
45
46
# File 'lib/diaspora/relayable.rb', line 36

def subscribers
  if root.author.local?
    if author.local?
      root.subscribers
    else
      root.subscribers.select(&:remote?).reject {|person| person.pod_id == author.pod_id }
    end
  else
    [root.author, author]
  end
end