Class: Blacklight::UserGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Blacklight::UserGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/blacklight/user_generator.rb
Instance Method Summary collapse
-
#generate_devise_assets ⇒ Object
Install Devise?.
-
#inject_blacklight_user_behavior ⇒ Object
Add Blacklight to the user model.
Instance Method Details
#generate_devise_assets ⇒ Object
Install Devise?
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/generators/blacklight/user_generator.rb', line 21 def generate_devise_assets return unless [:devise] gem "devise" gem "devise-guests", "~> 0.8" inside destination_root do Bundler.with_unbundled_env do run "bundle install" end end generate "devise:install" generate "devise", model_name.classify generate "devise_guests", model_name.classify gsub_file("config/initializers/devise.rb", "config.sign_out_via = :delete", "config.sign_out_via = :get") # Work around for https://github.com/heartcombo/devise/issues/5720 gsub_file("config/initializers/devise.rb", "# config.reload_routes = true", "config.reload_routes = false") end |
#inject_blacklight_user_behavior ⇒ Object
Add Blacklight to the user model
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/generators/blacklight/user_generator.rb', line 43 def inject_blacklight_user_behavior file_path = "app/models/#{model_name.underscore}.rb" if File.exist?(File.(file_path, destination_root)) inject_into_class file_path, model_name.classify do <<~EOS # Connects this user object to Blacklights Bookmarks. include Blacklight::User # Blacklight::User uses a method on your User class to get a user-displayable # label (e.g. login or identifier) for the account. Blacklight uses `email' by default. # self.string_display_key = :email EOS end else say_status "warning", <<~EOS, :yellow Blacklight authenticated user functionality not installed, as a user model could not be found at #{file_path}. If you used a different name, please re-run the migration and provide that name as an argument. E.g.: `rails -g blacklight:user client` EOS end end |