Sha256: 7d071ac92d9c53a541b101e25592bfb8432d80e91d5b3b1f8ed591486555f50e

Contents?: true

Size: 1001 Bytes

Versions: 74

Compression:

Stored size: 1001 Bytes

Contents

# frozen_string_literal: true
module Blacklight::User
  # 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)
    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

  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
end

Version data entries

74 entries across 74 versions & 2 rubygems

Version Path
blacklight-7.40.0 app/models/concerns/blacklight/user.rb
blacklight-7.39.0 app/models/concerns/blacklight/user.rb
blacklight-7.38.0 app/models/concerns/blacklight/user.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-7.37.0/app/models/concerns/blacklight/user.rb
blacklight-7.37.0 app/models/concerns/blacklight/user.rb
blacklight-7.36.2 app/models/concerns/blacklight/user.rb
blacklight-7.36.1 app/models/concerns/blacklight/user.rb
blacklight-7.36.0 app/models/concerns/blacklight/user.rb
blacklight-7.35.0 app/models/concerns/blacklight/user.rb
blacklight-7.34.0 app/models/concerns/blacklight/user.rb
blacklight-7.33.1 app/models/concerns/blacklight/user.rb
blacklight-7.33.0 app/models/concerns/blacklight/user.rb
blacklight-7.32.0 app/models/concerns/blacklight/user.rb
blacklight-7.31.0 app/models/concerns/blacklight/user.rb
blacklight-7.30.0 app/models/concerns/blacklight/user.rb
blacklight-7.29.0 app/models/concerns/blacklight/user.rb
blacklight-7.28.0 app/models/concerns/blacklight/user.rb
blacklight-7.27.1 app/models/concerns/blacklight/user.rb
blacklight-7.27.0 app/models/concerns/blacklight/user.rb
blacklight-7.26.1 app/models/concerns/blacklight/user.rb