Sha256: dbf732956e9c599cfcd4c1311d41048a267e0836ea8d1d9c0eb436c0460e5056

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 KB

Contents

require 'rails/generators'

module MetaReports
  module Generators
    class InstallEngineGenerator < Rails::Generators::Base
      source_root File.expand_path('../templates', __FILE__)
      
      desc 'Copy meta_reports migration, models, controllers, and views.'

      def create_migration_file
        Dir.chdir(Rails.root) do
          `rake meta_reports:install:migrations`
        end
      end
      
      def install_controller
        copy_file "controllers/reports_controller.rb", "app/controllers/meta_reports/reports_controller.rb"
      end

      def install_model
        copy_file "models/report.rb", "app/models/meta_reports/report.rb"
      end

      def install_views
        directory "views", "app/views/meta_reports/reports"
      end

      def mount_engine
        routes_file = "#{Rails.root}/config/routes.rb"
        unless open(routes_file).grep(/MetaReports::Engine/)
          insert_into_file(routes_file, :after => /routes.draw.do\n/) do
            %Q{
  # This line mounts MetaReports's routes at /reports by default.
  # This means, any requests to the /reports URL of your application will go to MetaReports::ReportsController#index.
  # If you would like to change where this extension is mounted, simply change '/reports' to something different.
  mount MetaReports::Engine => '/reports'

}
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
meta_reports-0.0.5 lib/generators/meta_reports/install_engine_generator.rb
meta_reports-0.0.4 lib/generators/meta_reports/install_engine_generator.rb