Sha256: 54a61373c45cb55619d1489986e999751bd4069b4b4f023b4f02ade71fb0dc9d

Contents?: true

Size: 1019 Bytes

Versions: 26

Compression:

Stored size: 1019 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

26 entries across 26 versions & 1 rubygems

Version Path
blacklight-6.25.0 app/models/concerns/blacklight/user.rb
blacklight-6.24.0 app/models/concerns/blacklight/user.rb
blacklight-6.23.0 app/models/concerns/blacklight/user.rb
blacklight-6.22.0 app/models/concerns/blacklight/user.rb
blacklight-6.21.0 app/models/concerns/blacklight/user.rb
blacklight-6.20.0 app/models/concerns/blacklight/user.rb
blacklight-6.19.2 app/models/concerns/blacklight/user.rb
blacklight-6.19.1 app/models/concerns/blacklight/user.rb
blacklight-6.19.0 app/models/concerns/blacklight/user.rb
blacklight-6.18.0 app/models/concerns/blacklight/user.rb
blacklight-6.17.0 app/models/concerns/blacklight/user.rb
blacklight-6.16.0 app/models/concerns/blacklight/user.rb
blacklight-6.15.0 app/models/concerns/blacklight/user.rb
blacklight-6.14.1 app/models/concerns/blacklight/user.rb
blacklight-6.14.0 app/models/concerns/blacklight/user.rb
blacklight-6.13.0 app/models/concerns/blacklight/user.rb
blacklight-6.12.0 app/models/concerns/blacklight/user.rb
blacklight-6.11.2 app/models/concerns/blacklight/user.rb
blacklight-6.11.1 app/models/concerns/blacklight/user.rb
blacklight-6.11.0 app/models/concerns/blacklight/user.rb