require 'rubygems/specification' require 'rails/generators/named_base' require 'rails/generators/resource_helpers' module Admin module Generators class ScaffoldControllerGenerator < Rails::Generators::NamedBase include Rails::Generators::ResourceHelpers source_root File.expand_path('templates', __dir__) class_option :prefix_name, banner: "admin", type: :string, default: "admin", desc: "Define the prefix of controller" class_option :parent_controller, banner: "admin", type: :string, default: "application", desc: "Define the parent controller" def create_controller_files # I think there should be a better way to detect if jbuilder is in use # If you know it, please let me know template "controllers/controller.rb.erb", File.join('app/controllers', prefix, class_path, "#{controller_file_name}_controller.rb") # create_file "app/controllers/a.rb", "# Add initialization content here" end def prefix options[:prefix_name] end def prefixed_class_name "#{prefix.capitalize}::#{class_name}" end def prefixed_controller_class_name "#{prefix.capitalize}::#{controller_class_name}" end def parent_controller_class_name options[:parent_controller].capitalize end end end end