-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inject route with namespace into existing blocks #41584
Inject route with namespace into existing blocks #41584
Conversation
This allows successive invocations of the `route` generator action to re-use existing `namespace` blocks.
1902f84
to
106e20d
Compare
@jonathanhefner I believe so. The only use case I really had was inserting into an existing namespace. 👍 |
routing_code = optimize_indentation(routing_code, base_indent + 2).lines.grep_v(/^[ ]{,#{prev_indent}}\S/).join | ||
end | ||
|
||
inject_into_file "config/routes.rb", routing_code, after: after_pattern, verbose: false, force: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about making the routes file configurable since draw
was added in #37892 ?
For example, with the admin gem I'm working on, it'd be great to be able to add draw :admin
to the main routes.rb and have our generators add routes to config/routes/admin.rb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds like a good idea. Though I would prefer to do it in a follow-up PR.
fyi #43950 |
Follow-up to rails#41584. Thor uses a regexp with its own capture groups when revoking an `inject_into_file` call. Thus an `:after` regexp containing capture groups will interfere with Thor's regexp. This commit changes the `:after` regexp we pass to `inject_into_file` so that it no longer contains capture groups. This commit also cleans up any newly-empty namespace blocks when revoking a route, since `inject_into_file` does not handle that. The majority of this commit is refactoring and clean-up. The actual regexp fix is just the following line: ```ruby namespace_pattern = /#{Regexp.escape namespace_match.to_s}/ ``` Fixes rails#43950.
This allows successive invocations of the
route
generator action to re-use existingnamespace
blocks.