Sha256: 4a1bfcaa3ec47622338dd323798b2fcd72523ca8ce313703a9bdc0fa699e92dd
Contents?: true
Size: 983 Bytes
Versions: 1
Compression:
Stored size: 983 Bytes
Contents
module Socialization module Liker def self.included(base) base.class_eval do # A like is the Like record of self liking a likeable record. has_many :likes, :as => :liker, :dependent => :destroy, :class_name => 'Like' def is_liker? true end def like!(likeable) raise ArgumentError, "#{likeable} is not likeable!" unless likeable.respond_to?(:is_likeable?) Like.create! :liker => self, :likeable => likeable end def unlike!(likeable) likeable.likings.where(:liker_type => self.class.to_s, :liker_id => self.id).each do |l| l.destroy end end def likes?(likeable) raise ArgumentError, "#{likeable} is not likeable!" unless likeable.respond_to?(:is_likeable?) && likeable.is_likeable? !self.likes.where(:likeable_type => likeable.class.to_s, :likeable_id => likeable.id).empty? end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
socialization-0.2.1 | lib/socialization/liker.rb |