Class: RESTFramework::Generators::ControllerGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- RESTFramework::Generators::ControllerGenerator
- Defined in:
- lib/rest_framework/generators/controller_generator.rb
Overview
:nocov:
Constant Summary collapse
- PATH_REGEX =
%r{^[a-z0-9][a-z0-9_/]+$}
Class Method Summary collapse
-
.namespace ⇒ Object
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.
Instance Method Summary collapse
Class Method Details
.namespace ⇒ Object
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.
43 44 45 |
# File 'lib/rest_framework/generators/controller_generator.rb', line 43 def self.namespace return RESTFrameworkCustomGeneratorControllerNamespace.new("rest_framework:controller") end |
Instance Method Details
#create_rest_controller_file ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rest_framework/generators/controller_generator.rb', line 47 def create_rest_controller_file unless PATH_REGEX.match?(self.path) raise StandardError, "Path isn't valid." end # Remove '_controller' from end of path, if it exists. cleaned_path = self.path.delete_suffix("_controller") content = <<~END class #{cleaned_path.camelize}Controller < #{[:parent_class]} include RESTFramework::#{ [:include_base] ? "BaseControllerMixin" : "ModelControllerMixin" } end END create_file("app/controllers/#{cleaned_path}_controller.rb", content) end |