Class: ActiveAdmin::Generators::InstallGenerator

Inherits:
ActiveRecord::Generators::Base
  • Object
show all
Defined in:
lib/generators/active_admin/install/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#copy_initializerObject



16
17
18
19
20
21
22
# File 'lib/generators/active_admin/install/install_generator.rb', line 16

def copy_initializer
  @underscored_user_name = name.underscore.gsub("/", "_")
  @use_authentication_method = options[:users].present?
  @skip_comments = options[:skip_comments]
  @use_webpacker = options[:use_webpacker]
  template "active_admin.rb.erb", "config/initializers/active_admin.rb"
end

#create_assetsObject



41
42
43
44
45
46
47
# File 'lib/generators/active_admin/install/install_generator.rb', line 41

def create_assets
  if options[:use_webpacker]
    generate "active_admin:webpacker"
  else
    generate "active_admin:assets"
  end
end

#create_migrationsObject



49
50
51
52
53
# File 'lib/generators/active_admin/install/install_generator.rb', line 49

def create_migrations
  unless options[:skip_comments]
    migration_template "migrations/create_active_admin_comments.rb.erb", "db/migrate/create_active_admin_comments.rb"
  end
end

#setup_directoryObject



24
25
26
27
28
29
30
31
# File 'lib/generators/active_admin/install/install_generator.rb', line 24

def setup_directory
  empty_directory "app/admin"
  template "dashboard.rb", "app/admin/dashboard.rb"
  if options[:users].present?
    @user_class = name
    template "admin_users.rb.erb", "app/admin/#{name.underscore.pluralize}.rb"
  end
end

#setup_routesObject



33
34
35
36
37
38
39
# File 'lib/generators/active_admin/install/install_generator.rb', line 33

def setup_routes
  if options[:users] # Ensure Active Admin routes occur after Devise routes so that Devise has higher priority
    inject_into_file "config/routes.rb", "\n  ActiveAdmin.routes(self)", after: /devise_for .*, ActiveAdmin::Devise\.config/
  else
    route "ActiveAdmin.routes(self)"
  end
end