Sha256: c25dc869c60e7787e0a199a98e41a07c83aad8a5b5b51e2f4b4125958edf0fd4

Contents?: true

Size: 1.51 KB

Versions: 20

Compression:

Stored size: 1.51 KB

Contents

require 'rails/generators/active_record'

module ActiveAdmin
  module Generators
    class InstallGenerator < ActiveRecord::Generators::Base
      desc "Installs Active Admin and generates the necessary migrations"
      argument :name, type: :string, default: "AdminUser"

      hook_for :users, default: "devise", desc: "Admin user generator to run. Skip with --skip-users"

      source_root File.expand_path("../templates", __FILE__)

      def copy_initializer
        @underscored_user_name = name.underscore
        @use_authentication_method = options[:users].present?
        template 'active_admin.rb.erb', 'config/initializers/active_admin.rb'
      end

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

      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

      def create_assets
        generate "active_admin:assets"
      end

      def create_migrations
        migration_template 'migrations/create_active_admin_comments.rb', 'db/migrate/create_active_admin_comments.rb'
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 3 rubygems

Version Path
activeadmin_addons-1.1.2 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/generators/active_admin/install/install_generator.rb
activeadmin_addons-1.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/generators/active_admin/install/install_generator.rb
yousty-activeadmin-1.0.17.pre lib/generators/active_admin/install/install_generator.rb
yousty-activeadmin-1.0.16.pre lib/generators/active_admin/install/install_generator.rb
activeadmin_addons-1.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/generators/active_admin/install/install_generator.rb
activeadmin_addons-1.0.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/generators/active_admin/install/install_generator.rb
activeadmin_addons-1.0.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/generators/active_admin/install/install_generator.rb
yousty-activeadmin-1.0.15.pre lib/generators/active_admin/install/install_generator.rb
yousty-activeadmin-1.0.14.pre lib/generators/active_admin/install/install_generator.rb
yousty-activeadmin-1.0.13.pre lib/generators/active_admin/install/install_generator.rb
yousty-activeadmin-1.0.12.pre lib/generators/active_admin/install/install_generator.rb
yousty-activeadmin-1.0.11.pre lib/generators/active_admin/install/install_generator.rb
yousty-activeadmin-1.0.10.pre lib/generators/active_admin/install/install_generator.rb
yousty-activeadmin-1.0.9.pre lib/generators/active_admin/install/install_generator.rb
yousty-activeadmin-1.0.8.pre lib/generators/active_admin/install/install_generator.rb
activeadmin-1.0.0.pre2 lib/generators/active_admin/install/install_generator.rb
activeadmin-1.0.0.pre1 lib/generators/active_admin/install/install_generator.rb
yousty-activeadmin-1.0.7.pre lib/generators/active_admin/install/install_generator.rb
yousty-activeadmin-1.0.6.pre lib/generators/active_admin/install/install_generator.rb
yousty-activeadmin-1.0.5.pre lib/generators/active_admin/install/install_generator.rb