class RESTFramework::Generators::ControllerGenerator

:nocov:

Constants

PATH_REGEX

Public Class Methods

namespace() click to toggle source

Some projects may not have the inflection “REST” as an acronym, which changes this generator to be namespaced in `r_e_s_t_framework`, which is weird.

# File lib/rest_framework/generators/controller_generator.rb, line 48
def self.namespace
  return RESTFrameworkCustomGeneratorControllerNamespace.new("rest_framework:controller")
end

Public Instance Methods

create_rest_controller_file() click to toggle source
# File lib/rest_framework/generators/controller_generator.rb, line 52
  def create_rest_controller_file
    unless (path_match = PATH_REGEX.match(self.path))
      raise StandardError.new("Path isn't correct.")
    end

    cleaned_path = path_match[1]
    content = <<~END
      class #{cleaned_path.camelize}Controller < #{options[:parent_class]}
        include RESTFramework::#{
          options[:include_base] ? "BaseControllerMixin" : "ModelControllerMixin"
        }
      end
    END
    create_file("app/controllers/#{path}_controller.rb", content)
  end