-
Notifications
You must be signed in to change notification settings - Fork 77
Support multiple controllers path #228
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
base: main
Are you sure you want to change the base?
Support multiple controllers path #228
Conversation
… to add controllers_paths method
0f13ad1 to
c420089
Compare
c420089 to
0bb6edb
Compare
0a54514 to
b122b8a
Compare
|
Hey @splittingred 👋🏽 , this PR is ready for review with the suggestion you made #213 (comment) |
| # Initialize the autoloaders with given controllers paths | ||
| # | ||
| # @param [String] controllers_path The path to Gruf Controllers | ||
| # @param [Array<String>] controllers_paths The path to Gruf Controllers | ||
| # | ||
| def load!(controllers_path:) | ||
| controllers(controllers_path: controllers_path) | ||
| def load!(controllers_path: nil, controllers_paths: []) | ||
| if controllers_path | ||
| ::Gruf.logger.warn('controllers_path is deprecated. Please use controllers_paths instead.') | ||
| controllers_paths = [controllers_path] | ||
| end | ||
| controllers(controllers_paths: controllers_paths) |
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.
Hey @splittingred 👋🏽
this is the change you requested in #213 (comment)
I have updated this accordingly. Let me know if you would like any other change
| # @param [Boolean] reloading | ||
| # @param [String] tag | ||
| # | ||
| def initialize(path:, reloading: nil, tag: nil) |
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.
This is a breaking change; can we avoid this by just checking to see if the passed variable is an Enumerable, or a String, and handle it accordingly? That would satisfy the requirement without breaking the public contract.
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.
i can leave the path keyword arg and additionally support paths. If both are passed then it would raise, otherwise path will be just wrapped in an array and set @paths
def initialize(path: nil, paths: [], reloading: nil, tag: nil)
raise ArgumentError(..) unless (path.nil? ^ paths.empty?)
@paths = paths.empty? ? [path] : pathsThere 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's fine - we just need to make sure there's a backward-compatible deprecation path.
What? Why?
I ran into a problem in a Rails app which was made up of multiple Rails engines. The problem was that two engines were using Gruf and when they were used in same Rails app, the Gruf config for
controllers_pathwas getting overridden.So to fix that problem, I patched Gruf to support multiple paths for controllers by adding a new config field
controllers_paths. This field defaults to[controllers_path]. Gruf uses thiscontrollers_pathsinstead ofcontrollers_patheverywhere, butcontrollers_pathis kept in config for backward compatibility.Note: I think the config should support something like
add_controllers_paths, instead of directly settingcontrollers_paths. That will allow multiple modules to add their controllers path without messing with the existing paths. Let me know if you like this idea, I will update the PRHow was it tested?
All the specs are passing