Sha256: ac163ea0cbaa8b8bf9bcc09e985a5fae50be3609388d04d5502b5e3c262d5d8d

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

###
# BookmarkSystem module
#
# This module defines common behavior in bookmark system
###
module BookmarkSystem
  ###
  # Bookmarkee module
  #
  # This module defines bookmarkee behavior in bookmark system
  ###
  module Bookmarkee
    ###
    # Extends ActiveSupport::Concern
    ###
    extend ActiveSupport::Concern

    ###
    # Included configuration
    ###
    included do
      ###
      # Has many bookmarkers association configuration
      ###
      has_many :bookmarkers, class_name: "BookmarkSystem::Bookmark", as: :bookmarkee, dependent: :destroy
    end

    ###
    # Specifies if self can be bookmarked by {Bookmarker} objects
    #
    # @return [Boolean]
    ###
    def is_bookmarkee?
      true
    end

    ###
    # Specifies if self is bookmarked by a {Bookmarker} object
    #
    # @param [Bookmarker] bookmarker - the {Bookmarker} object to test against
    # @return [Boolean]
    ###
    def bookmarked_by?(bookmarker)
      Bookmark.bookmarks?(bookmarker, self)
    end

    ###
    # Retrieves a scope of {Bookmark} objects that bookmarks self filtered {Bookmarker} type
    #
    # @param [Class] klass - the {Class} to filter
    # @return [ActiveRecord::Relation]
    ###
    def bookmarkers_by(klass)
      Bookmark.scope_by_bookmarkee(self).scope_by_bookmarker_type(klass)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bookmark_system-0.2.0 lib/bookmark_system/bookmarkee.rb