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