Sha256: cebe34a0d7b6997a577855a0ff32123a118c189b54f37e929fe3115859f8c2c9

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

###
# FollowSystem module
#
# This module defines common behavior in follow system
###
module FollowSystem
  ###
  # Followee module
  #
  # This module defines followee behavior in follow system
  ###
  module Followee
    ###
    # Extends ActiveSupport::Concern
    ###
    extend ActiveSupport::Concern

    ###
    # Included configuration
    ###
    included do
      ###
      # Has many followers association configuration
      ###
      has_many :followers, class_name: "FollowSystem::Follow", as: :followee, dependent: :destroy
    end

    ###
    # Specifies if self can be followed by {Follower} objects
    #
    # @return [Boolean]
    ###
    def is_followee?
      true
    end

    ###
    # Specifies if self is followed by a {Follower} object
    #
    # @param [Follower] follower - the {Follower} object to test against
    # @return [Boolean]
    ###
    def followed_by?(follower)
      Follow.follows?(follower, self)
    end

    ###
    # Retrieves a scope of {Follow} objects that follows self filtered {Follower} type
    #
    # @param [Class] klass - the {Class} to filter
    # @return [ActiveRecord::Relation]
    ###
    def followers_by(klass)
      Follow.scope_by_followee(self).scope_by_follower_type(klass)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
follow_system-0.2.0 lib/follow_system/followee.rb