-
Notifications
You must be signed in to change notification settings - Fork 30
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
feat: new overridable routing headers implementation #910
base: main
Are you sure you want to change the base?
feat: new overridable routing headers implementation #910
Conversation
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.
It would also probably be prudent to split this into two PRs, one for the gapic-common change and one for the generator template change. Because the template change depends on the gapic-common change, so we should first release a new gapic-common minor version, and then update the templates including updating the gapic-common dependency version.
# @private | ||
# Creates a new HeaderBinding. | ||
# | ||
def self.create field:, header_name: nil, regex: 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.
Is there a reason we're creating this separate factory method rather than just writing the constructor with this signature?
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.
Symmetry with the routing headers extractor/binding
@bindings = bindings || [] | ||
end | ||
|
||
def with_bindings(field:, header_name: nil, regex: 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 should be okay without the parens
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.
👍
|
||
module Gapic | ||
module RoutingHeaders | ||
class HeadersExtractor |
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.
Unless this class is @private
we need documentation for the class and its public methods.
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.
Will be @private
|
||
if header_binding.regex && !field_value.is_a?(::String) | ||
err_msg = "Header binding configuration is incorrect: regex" \ | ||
"is given with a non-string field #{field}.\n" \ |
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.
Did you mean #{field_value}
?
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.
yes, good catch
next unless field_value | ||
|
||
if header_binding.regex && !field_value.is_a?(::String) | ||
err_msg = "Header binding configuration is incorrect: regex" \ |
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.
you probably want a space after regex
.
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.
👍
curr_submessage = curr_submessage.send curr_field | ||
end | ||
|
||
return curr_submessage.to_s if curr_submessage |
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.
You can probably replace this line with simply curr_submessage&.to_s
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.
👍
field_path.each do |curr_field| | ||
return nil unless curr_submessage.respond_to? curr_field | ||
curr_submessage = curr_submessage.send curr_field | ||
end |
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.
A bit more idiomatic would be to use Enumerable#reduce
for the above:
final_submessage = field_path.reduce request do |curr_submessage, curr_field|
return nil unless curr_submessage.respond_to? curr_field
curr_submessage.send curr_field
end
Followed by:
final_submessage&.to_s
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.
👍
No description provided.