Class: Parrot::Comment

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/parrot/comment.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.following(other_comment) ⇒ Object



21
22
23
# File 'app/models/parrot/comment.rb', line 21

def self.following(other_comment)
  siblings_of(other_comment).where("id > #{other_comment.id}")
end

.siblings_of(other_comment) ⇒ Object



14
15
16
17
18
19
# File 'app/models/parrot/comment.rb', line 14

def self.siblings_of(other_comment)
  where(
    commentable_type: other_comment.commentable_type,
    commentable_id: other_comment.commentable_id
  )
end

Instance Method Details

#authorObject



25
26
27
# File 'app/models/parrot/comment.rb', line 25

def author
  Parrot.author_class.find_by_id author_id
end

#cache_author_dataObject

An author may delete it’s account, we cache/store it’s sensitive data



30
31
32
33
34
35
# File 'app/models/parrot/comment.rb', line 30

def cache_author_data
  return if author.nil?
  [:name, :email, :phone].each do |method|
    self.send(:"author_#{method}=", author.send(method)) if author.respond_to?(method)
  end
end