-
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?
Changes from all commits
c5e4f33
05f4b49
19cc2bd
db47704
1243be3
efd6160
0bb6edb
b122b8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,24 +20,24 @@ | |
| module Gruf | ||
| module Controllers | ||
| ## | ||
| # Handles autoloading of Gruf controllers in the application path. This allows for code reloading on Gruf | ||
| # Handles autoloading of Gruf controllers in the application paths. This allows for code reloading on Gruf | ||
| # controllers. | ||
| # | ||
| class Autoloader | ||
| include ::Gruf::Loggable | ||
|
|
||
| # @!attribute [r] path | ||
| # @return [String] The path for this autoloader | ||
| attr_reader :path | ||
| # @!attribute [r] paths | ||
| # @return [Array<String>] The paths for this autoloader | ||
| attr_reader :paths | ||
|
|
||
| ## | ||
| # @param [String] path | ||
| # @param [Array<String>] paths | ||
| # @param [Boolean] reloading | ||
| # @param [String] tag | ||
| # | ||
| def initialize(path:, reloading: nil, tag: nil) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 def initialize(path: nil, paths: [], reloading: nil, tag: nil)
raise ArgumentError(..) unless (path.nil? ^ paths.empty?)
@paths = paths.empty? ? [path] : paths
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| def initialize(paths:, reloading: nil, tag: nil) | ||
| super() | ||
| @path = path | ||
| @paths = paths | ||
| @loader = ::Zeitwerk::Loader.new | ||
| @loader.tag = tag || 'gruf-controllers' | ||
| @setup = false | ||
|
|
@@ -73,11 +73,14 @@ def with_fresh_controller(controller_name) | |
| def setup! | ||
| return true if @setup | ||
|
|
||
| return false unless File.directory?(@path) | ||
| directories = @paths.select { |path| File.directory?(path) } | ||
| return false unless directories.any? | ||
|
|
||
| @loader.enable_reloading if @reloading_enabled | ||
| @loader.ignore("#{@path}/**/*_pb.rb") | ||
| @loader.push_dir(@path) | ||
| directories.each do |path| | ||
| @loader.ignore("#{path}/**/*_pb.rb") | ||
| @loader.push_dir(path) | ||
| end | ||
| @loader.setup | ||
| # always eager load RPC files, so that the service binder can bind the Gruf::Controller instantiation | ||
| # to the gRPC Service classes | ||
|
|
||
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