Module: Diaspora::Likeable

Included in:
Comment, Post
Defined in:
lib/diaspora/likeable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(model) ⇒ Object


9
10
11
12
13
14
# File 'lib/diaspora/likeable.rb', line 9

def self.included(model)
  model.instance_eval do
    has_many :likes, -> { where(positive: true) }, dependent: :delete_all, as: :target
    has_many :dislikes, -> { where(positive: false) }, class_name: 'Like', dependent: :delete_all, as: :target
  end
end

Instance Method Details

#update_likes_counterInteger

Returns:

  • (Integer)

17
18
19
20
# File 'lib/diaspora/likeable.rb', line 17

def update_likes_counter
  self.class.where(id: self.id).
    update_all(likes_count: self.likes.count)
end