Sha256: 978373a2983c00102cb97a60b6663e8cdd36c8ff02c31c8e3b03ea8b1b505631
Contents?: true
Size: 1 KB
Versions: 3
Compression:
Stored size: 1 KB
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) if base.respond_to? :has_many base.send :has_many, :bookmarks, :dependent => :destroy, :as => :user base.send :has_many, :searches, :dependent => :destroy, :as => :user end end def bookmarks_for_documents documents = [] if documents.length > 0 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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
blacklight-6.0.2 | app/models/concerns/blacklight/user.rb |
blacklight-6.0.1 | app/models/concerns/blacklight/user.rb |
blacklight-6.0.0 | app/models/concerns/blacklight/user.rb |