-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generators: allow decorators not to match controller names
Decorator will respect `--model-name` passed to `scaffold_controller` or `controller` generator. That could be of a particular use to solve namespace issues (e.g. when controllers are namespaced and models are not). The specs have been refactored to reduce and DRY the code. Resolves #919.
- Loading branch information
1 parent
2836ea7
commit 250eb7b
Showing
3 changed files
with
123 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
require "rails/generators" | ||
require "rails/generators/rails/controller/controller_generator" | ||
require "rails/generators/rails/scaffold_controller/scaffold_controller_generator" | ||
require "rails/generators/model_helpers" | ||
|
||
module Rails | ||
module Generators | ||
class ControllerGenerator | ||
include Rails::Generators::ModelHelpers | ||
|
||
class_option :model_name, type: :string, desc: "ModelName to be used" | ||
|
||
hook_for :decorator, type: :boolean, default: true do |generator| | ||
invoke generator, [name.singularize] | ||
invoke generator, [options[:model_name] || name] | ||
end | ||
end | ||
|
||
class ScaffoldControllerGenerator | ||
hook_for :decorator, type: :boolean, default: true | ||
hook_for :decorator, type: :boolean, default: true do |generator| | ||
invoke generator, [options[:model_name] || name] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters