Skip to content
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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

davebenvenuti
Copy link
Contributor

@davebenvenuti davebenvenuti commented Jan 30, 2025

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 make MessageCompiler 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 on Field. This PR introduces a DecoratedField which provides this functionality and moves these helper methods out of MessageCompiler. The end result is more OO, and also makes it easier to introduce Codegen functionality outside of MessageCompiler. 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.

@davebenvenuti davebenvenuti marked this pull request as ready for review January 30, 2025 17:57
@davebenvenuti davebenvenuti mentioned this pull request Jan 30, 2025
@davebenvenuti davebenvenuti added the #gsd:43107 Ruby Language: RPC Code Generation for Shopify Internal APIs [GSD 43107] label Jan 30, 2025
Copy link
Contributor

@rwstauner rwstauner left a 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

lib/protoboeuf/decorated_field.rb Outdated Show resolved Hide resolved
test/decorated_field_test.rb Outdated Show resolved Hide resolved
test/decorated_field_test.rb Outdated Show resolved Hide resolved
Comment on lines +8 to +9
require "protoboeuf/codegen/type_helper"
require "protoboeuf/codegen/field"
Copy link
Contributor Author

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:

#183 (review)
#183 (comment)
#183 (comment)

Copy link
Contributor Author

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.

@davebenvenuti davebenvenuti force-pushed the davebenvenuti/decorated-field branch from ea7bac9 to ec488bc Compare January 31, 2025 18:45
@@ -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|
Copy link
Contributor Author

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.

@davebenvenuti davebenvenuti changed the title Introduce a DecoratedField to alleviate feature envy Introduce a ProtoBoeuf::CodeGen::Field to alleviate feature envy Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
#gsd:43107 Ruby Language: RPC Code Generation for Shopify Internal APIs [GSD 43107]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants