Sha256: 0705c1224aa452a71bbc6f19c25bbb34757c91f6e16d5e1edb3a0047f43fec9e
Contents?: true
Size: 1000 Bytes
Versions: 1
Compression:
Stored size: 1000 Bytes
Contents
# frozen_string_literal: true module Blacklight::User # This gives us an is_blacklight_user method that can be included in # the containing applications models. # SEE ALSO: The /lib/blacklight/engine.rb class for how when this # is injected into the hosting application through ActiveRecord::Base extend def self.included(base) return unless base.respond_to? :has_many base.send :has_many, :bookmarks, dependent: :destroy, as: :user base.send :has_many, :searches, dependent: :destroy, as: :user end def bookmarks_for_documents documents = [] if documents.any? bookmarks.where(document_type: documents.first.class.base_class.to_s, document_id: documents.map(&:id)) else [] end end def document_is_bookmarked?(document) bookmarks_for_documents([document]).any? end # returns a Bookmark object if there is one for document_id, else # nil. def existing_bookmark_for(document) bookmarks_for_documents([document]).first end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
blacklight-7.0.0.rc1 | app/models/concerns/blacklight/user.rb |