Sha256: b053a18c8ba19f722580cd8740fd5a8e4c17973a9ca3807125859339f50145f8

Contents?: true

Size: 1.74 KB

Versions: 7

Compression:

Stored size: 1.74 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"
      class_option :skip_comments, type: :boolean, default: false, desc: "Skip installation of comments"

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

      def copy_initializer
        @underscored_user_name = name.underscore.gsub('/', '_')
        @use_authentication_method = options[:users].present?
        @skip_comments = options[:skip_comments]
        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_users.rb.erb', "app/admin/#{name.underscore.pluralize}.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
        unless options[:skip_comments]
          migration_template 'migrations/create_active_admin_comments.rb.erb', 'db/migrate/create_active_admin_comments.rb'
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
activeadmin_addons-1.7.1 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/lib/generators/active_admin/install/install_generator.rb
activeadmin_addons-1.7.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/lib/generators/active_admin/install/install_generator.rb
activeadmin_addons-1.6.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/lib/generators/active_admin/install/install_generator.rb
activeadmin_addons-1.5.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-f71b375325eb/lib/generators/active_admin/install/install_generator.rb
activeadmin_addons-1.4.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-f71b375325eb/lib/generators/active_admin/install/install_generator.rb
activeadmin_addons-1.3.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/lib/generators/active_admin/install/install_generator.rb
activeadmin_addons-1.2.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/lib/generators/active_admin/install/install_generator.rb