Class: RailsAdmin::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Generators::Utils::InstanceMethods
Defined in:
lib/generators/rails_admin/install_generator.rb

Instance Method Summary collapse

Methods included from Generators::Utils::InstanceMethods

#ask_for, #display

Instance Method Details

#installObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/generators/rails_admin/install_generator.rb', line 16

def install
  if File.read(File.join(destination_root, 'config/routes.rb')).include?('mount RailsAdmin::Engine')
    display "Skipped route addition, since it's already there"
  else
    namespace = ask_for('Where do you want to mount rails_admin?', 'admin', _namespace)
    route("mount RailsAdmin::Engine => '/#{namespace}', as: 'rails_admin'")
  end
  if File.exist? File.join(destination_root, 'config/initializers/rails_admin.rb')
    insert_into_file 'config/initializers/rails_admin.rb', "  config.asset_source = :#{asset}\n", after: "RailsAdmin.config do |config|\n"
  else
    template 'initializer.erb', 'config/initializers/rails_admin.rb'
  end
  display "Using [#{asset}] for asset delivery method"
  case asset
  when 'webpack'
    configure_for_webpack
  when 'importmap'
    configure_for_importmap
  when 'webpacker'
    configure_for_webpacker5
  when 'vite'
    configure_for_vite
  when 'sprockets'
    configure_for_sprockets
  else
    raise "Unknown asset source: #{asset}"
  end
end