app/models/concerns/blacklight/user.rb in blacklight-7.40.0 vs app/models/concerns/blacklight/user.rb in blacklight-8.0.0.beta1

- old
+ new

@@ -1,16 +1,16 @@ # 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 + 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 - base.send :has_many, :bookmarks, dependent: :destroy, as: :user - base.send :has_many, :searches, dependent: :destroy, as: :user + 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)) @@ -25,7 +25,16 @@ # 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