Sha256: 0c88c95626c76d57a632926e6f5ea4204d3e4dddcd98d807b65278d9033c2dee

Contents?: true

Size: 1.08 KB

Versions: 21

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Blacklight::User
  extend ActiveSupport::Concern
  # SEE ALSO:  The lib/blacklight/generator/user_generator.rb class for where this
  # is generated into the hosting application.
  included do
    class_attribute :string_display_key

    has_many :bookmarks, dependent: :destroy, as: :user
    has_many :searches,  dependent: :destroy, as: :user
  end

  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

  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

  ##
  # @return [String] a user-displayable login/identifier for the user account
  def to_s
    string_display_key = self.class.string_display_key
    return send(string_display_key) if respond_to?(string_display_key)

    super
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
blacklight-8.6.1 app/models/concerns/blacklight/user.rb
blacklight-8.6.0 app/models/concerns/blacklight/user.rb
blacklight-8.5.1 app/models/concerns/blacklight/user.rb
blacklight-8.5.0 app/models/concerns/blacklight/user.rb
blacklight-8.4.0 app/models/concerns/blacklight/user.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-8.3.0/app/models/concerns/blacklight/user.rb
blacklight-8.3.0 app/models/concerns/blacklight/user.rb
blacklight-8.2.2 app/models/concerns/blacklight/user.rb
blacklight-8.2.1 app/models/concerns/blacklight/user.rb
blacklight-8.2.0 app/models/concerns/blacklight/user.rb
blacklight-8.1.0 app/models/concerns/blacklight/user.rb
blacklight-8.0.1 app/models/concerns/blacklight/user.rb
blacklight-8.0.0 app/models/concerns/blacklight/user.rb
blacklight-8.0.0.beta8 app/models/concerns/blacklight/user.rb
blacklight-8.0.0.beta7 app/models/concerns/blacklight/user.rb
blacklight-8.0.0.beta6 app/models/concerns/blacklight/user.rb
blacklight-8.0.0.beta5 app/models/concerns/blacklight/user.rb
blacklight-8.0.0.beta4 app/models/concerns/blacklight/user.rb
blacklight-8.0.0.beta3 app/models/concerns/blacklight/user.rb
blacklight-8.0.0.beta2 app/models/concerns/blacklight/user.rb