Class: Hibiki::Rails::Generators::ScaffoldGenerator
- Inherits:
-
Rails::Generators::ResourceGenerator
- Object
- Rails::Generators::ResourceGenerator
- Hibiki::Rails::Generators::ScaffoldGenerator
- Includes:
- ScaffoldHelpers
- Defined in:
- lib/generators/hibiki/rails/scaffold/scaffold_generator.rb
Overview
The headline command: model + migration + route + a reactive CRUD
resource, the way rails g scaffold emits a plain one.
Subclasses Rails' ResourceGenerator, which is the model generator plus the resource_route hook — so the model, its migration, its fixtures and the route all come from Rails itself, unchanged. Only the controller half is ours.
Stock rails g scaffold is deliberately left alone: this lives under
its own namespace and nothing here registers as Rails' scaffold_controller.
Instance Method Summary collapse
-
#initialize ⇒ ScaffoldGenerator
constructor
A new instance of ScaffoldGenerator.
- #invoke_hibiki_scaffold_controller ⇒ Object
Constructor Details
#initialize ⇒ ScaffoldGenerator
Returns a new instance of ScaffoldGenerator.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/generators/hibiki/rails/scaffold/scaffold_generator.rb', line 49 def initialize(...) super return if attributes.any? # Raised HERE rather than in a task, because the inherited orm hook # runs first and would otherwise write a model and a migration before # the controller generator discovered it had nothing to work from. raise ::Rails::Generators::Error, <<~MESSAGE.strip #{self.class.} needs at least one field — the migration has not run when the views are generated, so the schema cannot be read yet. For a model that already exists, use: bin/rails g hibiki:rails:scaffold_controller #{name} MESSAGE end |
Instance Method Details
#invoke_hibiki_scaffold_controller ⇒ Object
65 66 67 68 69 |
# File 'lib/generators/hibiki/rails/scaffold/scaffold_generator.rb', line 65 def invoke_hibiki_scaffold_controller # to_argv, never GeneratedAttribute#to_s: `title:string!` round-trips # through to_s as "title:string{null}", which .parse then rejects. invoke ScaffoldControllerGenerator, [name, *attributes.map { to_argv(it) }] end |