Sha256: 22e56d1f576e4c4e0a224d4faf31c599f40ae1ab38557425569079fcfafcbd0f

Contents?: true

Size: 1.26 KB

Versions: 19

Compression:

Stored size: 1.26 KB

Contents

# -*- encoding : utf-8 -*-
module Blacklight::User
  
  extend Deprecation
  self.deprecation_horizon = 'blacklight 6.0'

  # 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, document_id: documents.map { |x| x.id})
    else
      []
    end
  end

  def bookmarked_document_ids
    Deprecation.warn self, "The User#bookmarked_document_ids method is deprecated and will be removed in Blacklight 6.0"

    self.bookmarks.pluck(:document_id)
  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

19 entries across 19 versions & 1 rubygems

Version Path
blacklight-5.9.4 lib/blacklight/user.rb
blacklight-5.9.3 lib/blacklight/user.rb
blacklight-5.9.2 lib/blacklight/user.rb
blacklight-5.9.1 lib/blacklight/user.rb
blacklight-5.9.0 lib/blacklight/user.rb
blacklight-5.8.2 lib/blacklight/user.rb
blacklight-5.8.1 lib/blacklight/user.rb
blacklight-5.8.0 lib/blacklight/user.rb
blacklight-5.7.2 lib/blacklight/user.rb
blacklight-5.5.4 lib/blacklight/user.rb
blacklight-5.7.1 lib/blacklight/user.rb
blacklight-5.7.0 lib/blacklight/user.rb
blacklight-5.6.0 lib/blacklight/user.rb
blacklight-5.5.3 lib/blacklight/user.rb
blacklight-5.5.2 lib/blacklight/user.rb
blacklight-5.5.1 lib/blacklight/user.rb
blacklight-5.5.0 lib/blacklight/user.rb
blacklight-5.4.0 lib/blacklight/user.rb
blacklight-5.4.0.rc1 lib/blacklight/user.rb