Sha256: 32e202c84bbc02279bc0829280e8b0816817dbeb748de827ba11d26a7d7a3798

Contents?: true

Size: 1.24 KB

Versions: 15

Compression:

Stored size: 1.24 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(&:id))
    else
      []
    end
  end

  def bookmarked_document_ids
    self.bookmarks.pluck(:document_id)
  end
  deprecation_deprecate bookmarked_document_ids: "use current_user.bookmarks.pluck(:document_id) instead"

  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

15 entries across 15 versions & 1 rubygems

Version Path
blacklight-5.19.2 app/models/concerns/blacklight/user.rb
blacklight-5.19.1 app/models/concerns/blacklight/user.rb
blacklight-5.19.0 app/models/concerns/blacklight/user.rb
blacklight-5.18.0 app/models/concerns/blacklight/user.rb
blacklight-5.17.2 app/models/concerns/blacklight/user.rb
blacklight-5.17.1 app/models/concerns/blacklight/user.rb
blacklight-5.17.0 app/models/concerns/blacklight/user.rb
blacklight-5.16.4 app/models/concerns/blacklight/user.rb
blacklight-5.16.3 app/models/concerns/blacklight/user.rb
blacklight-5.16.2 app/models/concerns/blacklight/user.rb
blacklight-5.16.1 app/models/concerns/blacklight/user.rb
blacklight-5.16.0 app/models/concerns/blacklight/user.rb
blacklight-5.15.0 lib/blacklight/user.rb
blacklight-5.14.0 lib/blacklight/user.rb
blacklight-5.13.1 lib/blacklight/user.rb