Skip to content

Commit 04e3cf0

Browse files
authored
Consolidate generated additions to the User class (#3341)
Give the string_display_key a default value
1 parent b901630 commit 04e3cf0

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

app/models/concerns/blacklight/user.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Blacklight::User
55
# SEE ALSO: The lib/blacklight/generator/user_generator.rb class for where this
66
# is generated into the hosting application.
77
included do
8-
class_attribute :string_display_key
8+
class_attribute :string_display_key, default: :email
99

1010
has_many :bookmarks, dependent: :destroy, as: :user
1111
has_many :searches, dependent: :destroy, as: :user

lib/generators/blacklight/user_generator.rb

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@ def generate_devise_assets
3434
generate "devise", model_name.classify
3535
generate "devise_guests", model_name.classify
3636

37-
# add the #to_s to the model.
38-
insert_into_file("app/models/#{model_name}.rb", before: /end(\n| )*$/) do
39-
"\n # Configuration added by Blacklight; Blacklight::User uses a method key on your\n" \
40-
" # user class to get a user-displayable login/identifier for\n" \
41-
" # the account.\n" \
42-
" self.string_display_key ||= :email\n"
43-
end
4437
gsub_file("config/initializers/devise.rb", "config.sign_out_via = :delete", "config.sign_out_via = :get")
4538
end
4639

@@ -49,13 +42,19 @@ def inject_blacklight_user_behavior
4942
file_path = "app/models/#{model_name.underscore}.rb"
5043
if File.exist?(File.expand_path(file_path, destination_root))
5144
inject_into_class file_path, model_name.classify do
52-
"\n # Connects this user object to Blacklights Bookmarks." \
53-
"\n include Blacklight::User\n"
45+
<<~EOS
46+
# Connects this user object to Blacklights Bookmarks.
47+
include Blacklight::User
48+
49+
# Blacklight::User uses a method on your User class to get a user-displayable
50+
# label (e.g. login or identifier) for the account. Blacklight uses `email' by default.
51+
# self.string_display_key = :email
52+
EOS
5453
end
5554
else
5655
say_status "warning", <<~EOS, :yellow
5756
Blacklight authenticated user functionality not installed, as a user model
58-
could not be found at /app/models/user.rb. If you used a different name,
57+
could not be found at #{file_path}. If you used a different name,
5958
please re-run the migration and provide that name as an argument. E.g.:
6059
6160
`rails -g blacklight:user client`

0 commit comments

Comments
 (0)