Sha256: c9c001fa66ad3f9cbb7b0639f3e891fdedd39a6b357eca2344a680cf6aa77565

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

Rails.application.eager_load!
require "rails/generators/base"

module Administrate
  module Generators
    class InstallGenerator < Rails::Generators::Base
      source_root File.expand_path("../templates", __FILE__)

      def create_dashboard_controller
        copy_file(
          "application_controller.rb",
          "app/controllers/admin/application_controller.rb"
        )
      end

      def create_dashboard_manifest
        template(
          "dashboard_manifest.rb.erb",
          "app/dashboards/dashboard_manifest.rb"
        )
      end

      def insert_dashboard_routes
        route(dashboard_routes)
      end

      private

      def dashboard_resources
        valid_dashboard_models.map do |model|
          model.to_s.pluralize.underscore
        end
      end

      def valid_dashboard_models
        database_models.reject { |model| model.to_s.include?("::") }
      end

      def database_models
        ActiveRecord::Base.descendants
      end

      def dashboard_routes
        File.read(routes_file_path)
      end

      def routes_file_path
        File.expand_path(find_in_source_paths("routes.rb"))
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
administrate-0.0.2 lib/generators/administrate/install/install_generator.rb