Module: Likeable::ClassMethods

Defined in:
lib/likeable.rb

Overview

Class Methods ### —————– # allows us to setup callbacks when creating likes after_like :notify_users allows us to setup callbacks when destroying likes after_unlike :notify_users

Instance Method Summary collapse

Instance Method Details

#after_like(*methods) ⇒ Object



110
111
112
113
114
115
116
# File 'lib/likeable.rb', line 110

def after_like(*methods)
  define_method(:after_like) do |like|
    methods.each do |method|
      eval("#{method}(like)")
    end
  end
end

#after_unlike(*methods) ⇒ Object



118
119
120
121
122
123
124
# File 'lib/likeable.rb', line 118

def after_unlike(*methods)
  define_method(:after_unlike) do |user|
    methods.each do |method|
      eval("#{method}(user)")
    end
  end
end

#all_liked_by(user) ⇒ Object



105
106
107
108
# File 'lib/likeable.rb', line 105

def all_liked_by(user)
  ids = all_liked_ids_by(user)
  Likeable.find_many(self, ids)
end

#all_liked_ids_by(user) ⇒ Object



100
101
102
103
# File 'lib/likeable.rb', line 100

def all_liked_ids_by(user)
  key = user.like_key(self.to_s.downcase)
  ids = (Likeable.redis.hkeys(key)||[]).map {|id| Likeable.cast_id(id)}
end