Sha256: b2fe688034078a292585a577c4339fbef5e1a1f9e2e878563ce2e933cac74164

Contents?: true

Size: 1.31 KB

Versions: 24

Compression:

Stored size: 1.31 KB

Contents

require 'active_support'
require 'active_support/core_ext'
require 'string/builder'
require 'thor'

module Eucalypt
  module Generators
    class Controller < Thor::Group
      include Thor::Actions
      include Eucalypt::Helpers
      using String::Builder

      def self.source_root
        File.join File.dirname(__dir__), 'templates'
      end

      def generate(spec: true, rest: false, policy: false, headless: false, name:)
        controller = Inflect.new(:controller, name)

        route = '/' << (rest ? controller.route_name.pluralize : controller.route_name)

        controller_file_name = String.build do |s|
          s << 'policy_' if policy
          s << 'rest_' if rest
          s << 'controller.tt'
        end
        controller_template = File.join 'controller', controller_file_name

        helper = Inflect.new(:helper, controller.resource)

        config = {
          route: route,
          constant: controller.constant,
          class_name: controller.class_name,
          helper_class_name: helper.class_name,
          resource: controller.resource,
          resources: controller.resources,
          headless: headless
        }

        template(controller_template, controller.file_path, config)
        template("controller_spec.tt", controller.spec_path, config) if spec
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
eucalypt-0.8.0 lib/eucalypt/generate/namespaces/generate-controller/generators/controller.rb
eucalypt-0.7.2 lib/eucalypt/generate/namespaces/generate-controller/generators/controller.rb
eucalypt-0.7.1 lib/eucalypt/generate/namespaces/generate-controller/generators/controller.rb
eucalypt-0.7.0 lib/eucalypt/generate/namespaces/generate-controller/generators/controller.rb
eucalypt-0.6.2 lib/eucalypt/generate/namespaces/generate-controller/generators/controller.rb
eucalypt-0.6.1 lib/eucalypt/generate/namespaces/generate-controller/generators/controller.rb
eucalypt-0.6.0 lib/eucalypt/generate/namespaces/generate-controller/generators/controller.rb
eucalypt-0.5.4 lib/eucalypt/generate/namespaces/generate-controller/generators/controller.rb
eucalypt-0.5.3 lib/eucalypt/generate/namespaces/generate-controller/generators/controller.rb
eucalypt-0.5.2 lib/eucalypt/generate/namespaces/generate-controller/generators/controller.rb
eucalypt-0.5.1 lib/eucalypt/generate/namespaces/generate-controller/generators/controller.rb
eucalypt-0.5.0 lib/eucalypt/generate/namespaces/generate-controller/generators/controller.rb
eucalypt-0.4.2 lib/eucalypt/generate/namespaces/generate-controller/generators/controller.rb
eucalypt-0.4.1 lib/eucalypt/generate/namespaces/generate-controller/generators/controller.rb
eucalypt-0.4.0 lib/eucalypt/generate/namespaces/generate-controller/generators/controller.rb
eucalypt-0.3.5 lib/eucalypt/generate/namespaces/generate-controller/generators/controller.rb
eucalypt-0.3.4 lib/eucalypt/generate/namespaces/generate-controller/generators/controller.rb
eucalypt-0.3.3 lib/eucalypt/generate/namespaces/generate-controller/generators/controller.rb
eucalypt-0.3.2 lib/eucalypt/generate/namespaces/generate-controller/generators/controller.rb
eucalypt-0.3.1 lib/eucalypt/generate/namespaces/generate-controller/generators/controller.rb