Module: Blacklight::User
- Defined in:
- app/models/concerns/blacklight/user.rb
Class Method Summary collapse
-
.included(base) ⇒ Object
This gives us an is_blacklight_user method that can be included in the containing applications models.
Instance Method Summary collapse
- #bookmarks_for_documents(documents = []) ⇒ Object
- #document_is_bookmarked?(document) ⇒ Boolean
-
#existing_bookmark_for(document) ⇒ Object
returns a Bookmark object if there is one for document_id, else nil.
Class Method Details
.included(base) ⇒ Object
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
7 8 9 10 11 |
# File 'app/models/concerns/blacklight/user.rb', line 7 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 |
Instance Method Details
#bookmarks_for_documents(documents = []) ⇒ Object
13 14 15 16 17 18 19 |
# File 'app/models/concerns/blacklight/user.rb', line 13 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 |
#document_is_bookmarked?(document) ⇒ Boolean
21 22 23 |
# File 'app/models/concerns/blacklight/user.rb', line 21 def document_is_bookmarked?(document) bookmarks_for_documents([document]).any? end |
#existing_bookmark_for(document) ⇒ Object
returns a Bookmark object if there is one for document_id, else nil.
27 28 29 |
# File 'app/models/concerns/blacklight/user.rb', line 27 def existing_bookmark_for(document) bookmarks_for_documents([document]).first end |