Sha256: 65d4c56190756edcb81eb4c3ee1100fd7f16c48f9f39635928cbb1763f3aefa8

Contents?: true

Size: 1.15 KB

Versions: 6

Compression:

Stored size: 1.15 KB

Contents

###
# LikeSystem module
#
# This module defines common behavior in like system
###
module LikeSystem
  ###
  # Likee module
  #
  # This module defines likee behavior in like system
  ###
  module Likee
    ###
    # Extends ActiveSupport::Concern
    ###
    extend ActiveSupport::Concern

    ###
    # Included configuration
    ###
    included do
      ###
      # Has many likers association configuration
      ###
      has_many :likers, class_name: "LikeSystem::Like", as: :likee, dependent: :destroy
    end

    ###
    # Specifies if self can be liked by {Liker} objects
    #
    # @return [Boolean]
    ###
    def is_likee?
      true
    end

    ###
    # Specifies if self is liked by a {Liker} object
    #
    # @param [Liker] liker - the {Liker} object to test against
    # @return [Boolean]
    ###
    def liked_by?(liker)
      Like.likes?(liker, self)
    end

    ###
    # Retrieves a scope of {Like} objects that likes self filtered {Liker} type
    #
    # @param [Class] klass - the {Class} to filter
    # @return [ActiveRecord::Relation]
    ###
    def likers_by(klass)
      Like.scope_by_likee(self).scope_by_liker_type(klass)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
like_system-0.1.1 lib/like_system/likee.rb
like_system-0.1.0 lib/like_system/likee.rb
like_system-0.0.9 lib/like_system/likee.rb
like_system-0.0.8 lib/like_system/likee.rb
like_system-0.0.7 lib/like_system/likee.rb
like_system-0.0.6 lib/like_system/likee.rb