Sha256: a9c9ab38491894385a51d88957c4630cbe1862fb105dc944e5598ba35755a024

Contents?: true

Size: 651 Bytes

Versions: 3

Compression:

Stored size: 651 Bytes

Contents

module Socialization
  module Likeable
    def self.included(base)
      base.class_eval do
        # A liking is the Like record of the liker liking self.
        has_many :likings, :as => :likeable, :dependent => :destroy, :class_name => 'Like'

        def is_likeable?
          true
        end

        def liked_by?(liker)
          raise ArgumentError, "#{liker} is not a liker!" unless liker.respond_to?(:is_liker?) && liker.is_liker?
          !self.likings.where(:liker_type => liker.class.to_s, :liker_id => liker.id).empty?
        end

        def likers
          self.likings.map { |l| l.liker }
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
socialization-0.2.2 lib/socialization/likeable.rb
socialization-0.2.1 lib/socialization/likeable.rb
socialization-0.2.0 lib/socialization/likeable.rb