Sha256: 8e946e8b8d0b929894ebbfeb90af610ee63f10c4e4bc3ea4a50c889b36994b51

Contents?: true

Size: 1.53 KB

Versions: 19

Compression:

Stored size: 1.53 KB

Contents

module Cmor
  module Core
    module Backend
      module Generators
        # Example:
        #
        #     rails g cmor:core:backend:resources_controller -c Cmor::Services::ServicesController
        #
        class ResourcesControllerGenerator < Rails::Generators::Base
          desc 'Generates a resources 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 'resources_controller.rb', target_filename
          end

          def generate_routes
            route "resources :#{resources_route_name}"
          end

          private

          def resources_route_name
            @resources_route_name ||= controller_class.gsub(current_engine.chomp('Engine'), '').chomp('Controller').underscore
          end

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

          def target_filename
            @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

19 entries across 19 versions & 1 rubygems

Version Path
cmor_core_backend-0.0.27.pre lib/generators/cmor/core/backend/resources_controller/resources_controller_generator.rb
cmor_core_backend-0.0.26.pre lib/generators/cmor/core/backend/resources_controller/resources_controller_generator.rb
cmor_core_backend-0.0.25.pre lib/generators/cmor/core/backend/resources_controller/resources_controller_generator.rb
cmor_core_backend-0.0.24.pre lib/generators/cmor/core/backend/resources_controller/resources_controller_generator.rb
cmor_core_backend-0.0.22.pre lib/generators/cmor/core/backend/resources_controller/resources_controller_generator.rb
cmor_core_backend-0.0.21.pre lib/generators/cmor/core/backend/resources_controller/resources_controller_generator.rb
cmor_core_backend-0.0.20.pre lib/generators/cmor/core/backend/resources_controller/resources_controller_generator.rb
cmor_core_backend-0.0.19.pre lib/generators/cmor/core/backend/resources_controller/resources_controller_generator.rb
cmor_core_backend-0.0.18.pre lib/generators/cmor/core/backend/resources_controller/resources_controller_generator.rb
cmor_core_backend-0.0.17.pre lib/generators/cmor/core/backend/resources_controller/resources_controller_generator.rb
cmor_core_backend-0.0.15.pre lib/generators/cmor/core/backend/resources_controller/resources_controller_generator.rb
cmor_core_backend-0.0.14.pre lib/generators/cmor/core/backend/resources_controller/resources_controller_generator.rb
cmor_core_backend-0.0.13.pre lib/generators/cmor/core/backend/resources_controller/resources_controller_generator.rb
cmor_core_backend-0.0.12.pre lib/generators/cmor/core/backend/resources_controller/resources_controller_generator.rb
cmor_core_backend-0.0.11.pre lib/generators/cmor/core/backend/resources_controller/resources_controller_generator.rb
cmor_core_backend-0.0.10.pre lib/generators/cmor/core/backend/resources_controller/resources_controller_generator.rb
cmor_core_backend-0.0.9.pre lib/generators/cmor/core/backend/resources_controller/resources_controller_generator.rb
cmor_core_backend-0.0.8.pre lib/generators/cmor/core/backend/resources_controller/resources_controller_generator.rb
cmor_core_backend-0.0.7.pre lib/generators/cmor/core/backend/resources_controller/resources_controller_generator.rb