-
Notifications
You must be signed in to change notification settings - Fork 5
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
Introduce a ProtoBoeuf::CodeGen::Field to alleviate feature envy #181
base: main
Are you sure you want to change the base?
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.
Overall approve the idea/code but with an obligatory nitpick on the name and a few notes on the tests
require "protoboeuf/codegen/type_helper" | ||
require "protoboeuf/codegen/field" |
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.
Not 100% sure whether require
inside the class is more appropriate than autoload
. See this discussion:
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'm also not convinced this is worth blocking this PR over, but I'd like to resolve this as a best practice in the near future.
ea7bac9
to
ec488bc
Compare
@@ -74,7 +74,7 @@ rule ".rb" => ["%X.proto"] + codegen_rb_files do |t| | |||
File.binwrite(t.name, ProtoBoeuf::CodeGen.new(unit).to_ruby(dest, options)) | |||
end | |||
|
|||
rule ".rb" => "%X" do |t| | |||
rule %r{lib/protoboeuf/google/.+\.rb} => "%X" do |t| |
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.
lib/protoboeuf/codegen.rb
was getting caught here with the addition of the lib/protoboeuf/codegen
directory, which we don't want.
While working on Hash serialization support I found myself wanting to define a new compiler which our existing
ProtoBoeuf::CodeGen::MessageCompiler
could delegate to. Those changes required several private helper methods which started to makeMessageCompiler
feel cluttered. There were also a number of helper methods like#repeated?(field)
or#optional?(field)
which feel more like functionality we wish we had right onField
. This PR introduces aDecoratedField
which provides this functionality and moves these helper methods out ofMessageCompiler
. The end result is more OO, and also makes it easier to introduce Codegen functionality outside ofMessageCompiler
. Alternatively, these helper methods could have just been made into class methods to make them globally accessible, but that felt like more of a hack.