Sha256: 637261af033c94d489d06a617dadc0b2be202f0dafb452202081fda5a7373bdd

Contents?: true

Size: 1.25 KB

Versions: 49

Compression:

Stored size: 1.25 KB

Contents

module Cmor
  module Core
    module Frontend
      module Generators
        # Example:
        #
        #     rails g cmor:core:frontend:resource_controller -c CurrentUsersController -m User
        #
        class ResourceControllerGenerator < Rails::Generators::Base
          desc 'Generates a singular resource controller with CRUD actions.'

          source_root File.expand_path('../templates', __FILE__)

          class_option :controller_class, type: 'string', aliases: '-c'
          class_option :resource_class, type: 'string', aliases: '-m'

          def generate_controller
            template 'resource_controller.rb', target_filename
          end

          private

          def current_engine
            @current_engine ||= File.open("config/routes.rb", &:readline).split('.').first
          end

          def target_filename
            "app/controllers/#{controller_class.underscore}.rb"
          end

          def controller_class
            @controller_class ||= options[:controller_class]
          end

          def resource_class
            controller_class.chomp('Controller').singularize
          end

          def params_name
            resource_class.demodulize.underscore
          end
        end
      end
    end
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
cmor_core_frontend-0.0.60.pre lib/generators/cmor/core/frontend/resource_controller/resource_controller_generator.rb
cmor_core_frontend-0.0.59.pre lib/generators/cmor/core/frontend/resource_controller/resource_controller_generator.rb
cmor_core_frontend-0.0.58.pre lib/generators/cmor/core/frontend/resource_controller/resource_controller_generator.rb
cmor_core_frontend-0.0.57.pre lib/generators/cmor/core/frontend/resource_controller/resource_controller_generator.rb
cmor_core_frontend-0.0.56.pre lib/generators/cmor/core/frontend/resource_controller/resource_controller_generator.rb
cmor_core_frontend-0.0.55.pre lib/generators/cmor/core/frontend/resource_controller/resource_controller_generator.rb
cmor_core_frontend-0.0.54.pre lib/generators/cmor/core/frontend/resource_controller/resource_controller_generator.rb
cmor_core_frontend-0.0.53.pre lib/generators/cmor/core/frontend/resource_controller/resource_controller_generator.rb
cmor_core_frontend-0.0.52.pre lib/generators/cmor/core/frontend/resource_controller/resource_controller_generator.rb
cmor_core_frontend-0.0.51.pre lib/generators/cmor/core/frontend/resource_controller/resource_controller_generator.rb
cmor_core_frontend-0.0.50.pre lib/generators/cmor/core/frontend/resource_controller/resource_controller_generator.rb
cmor_core_frontend-0.0.49.pre lib/generators/cmor/core/frontend/resource_controller/resource_controller_generator.rb
cmor_core_frontend-0.0.48.pre lib/generators/cmor/core/frontend/resource_controller/resource_controller_generator.rb
cmor_core_frontend-0.0.45.pre lib/generators/cmor/core/frontend/resource_controller/resource_controller_generator.rb
cmor_core_frontend-0.0.44.pre lib/generators/cmor/core/frontend/resource_controller/resource_controller_generator.rb
cmor_core_frontend-0.0.43.pre lib/generators/cmor/core/frontend/resource_controller/resource_controller_generator.rb
cmor_core_frontend-0.0.42.pre lib/generators/cmor/core/frontend/resource_controller/resource_controller_generator.rb
cmor_core_frontend-0.0.41.pre lib/generators/cmor/core/frontend/resource_controller/resource_controller_generator.rb
cmor_core_frontend-0.0.40.pre lib/generators/cmor/core/frontend/resource_controller/resource_controller_generator.rb
cmor_core_frontend-0.0.39.pre lib/generators/cmor/core/frontend/resource_controller/resource_controller_generator.rb