Sha256: 830699360c14a4421d68ed424bffe7a9228126359e18ad41ad30bcfa19d667aa

Contents?: true

Size: 1.42 KB

Versions: 10

Compression:

Stored size: 1.42 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

      def run_dashboard_generators
        singular_dashboard_resources.each do |resource|
          Rails::Generators.invoke("administrate:dashboard", [resource])
        end
      end

      private

      def singular_dashboard_resources
        dashboard_resources.map(&:singularize)
      end

      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

10 entries across 10 versions & 1 rubygems

Version Path
administrate-0.1.0 lib/generators/administrate/install/install_generator.rb
administrate-0.0.12 lib/generators/administrate/install/install_generator.rb
administrate-0.0.11 lib/generators/administrate/install/install_generator.rb
administrate-0.0.10 lib/generators/administrate/install/install_generator.rb
administrate-0.0.9 lib/generators/administrate/install/install_generator.rb
administrate-0.0.8 lib/generators/administrate/install/install_generator.rb
administrate-0.0.7 lib/generators/administrate/install/install_generator.rb
administrate-0.0.6 lib/generators/administrate/install/install_generator.rb
administrate-0.0.4 lib/generators/administrate/install/install_generator.rb
administrate-0.0.3 lib/generators/administrate/install/install_generator.rb