Module: Blacklight::User

Defined in:
app/models/concerns/blacklight/user.rb

Class Method Summary collapse

Instance Method Summary collapse

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
12
# 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



14
15
16
17
18
19
20
# File 'app/models/concerns/blacklight/user.rb', line 14

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

Returns:

  • (Boolean)


22
23
24
# File 'app/models/concerns/blacklight/user.rb', line 22

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.



28
29
30
# File 'app/models/concerns/blacklight/user.rb', line 28

def existing_bookmark_for(document)
  bookmarks_for_documents([document]).first
end