Sha256: 9da08d695a39414e9b4752820b3f9996b75df8d2abdb9012d1cd9adb41d99366

Contents?: true

Size: 962 Bytes

Versions: 2

Compression:

Stored size: 962 Bytes

Contents

module AdminScaffold
  module Generators
    class AdminScaffoldGenerator < Rails::Generators::NamedBase
      source_root File.expand_path('../templates', __FILE__)
      namespace 'admin_scaffold'

      hook_for :scaffold, in: :rails, default: true do |instance, generator|
        attributes = instance.name.camelize.constantize.columns
                      .reject{|c| %w[id updated_at created_at].include? c.name }
                      .map!{|c| "#{c.name}:#{c.type}"}
        arguments = ["admin/#{instance.name}"] + (instance.args.presence || attributes)
        instance.invoke generator, arguments, force: true, test_framework: false, migration: false, parent: instance.name
      end

      def inherit_admin_controller
        gsub_file "app/controllers/admin/#{plural_name}_controller.rb", 'ApplicationController', 'AdminController'
      end

      def remove_namespace_module
        remove_file 'app/models/admin.rb'
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
adminscaffold-1.0.1 lib/generators/admin_scaffold/admin_scaffold_generator.rb
adminscaffold-1.0.0 lib/generators/admin_scaffold/admin_scaffold_generator.rb