-
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
QOL make our gem requireable and autoload/eager load some constants #171
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.
Makes sense, just a few small things to fix
cafa5bd
to
ecdc7b5
Compare
lib/protoboeuf/google.rb
Outdated
|
||
# There isn't a clean 1:1 mapping between constants and *.rb files, so eager load instead of autoload. | ||
|
||
Dir[File.expand_path("google/**/*.rb", __dir__)].each { |file| require file } |
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'd prefer we don't do this pattern, and rather generate the requires as part of our .proto
to .rb
step.
2 reasons:
- It's important to know what we're requiring
- I'm not sure if directory listings are sorted (they weren't in the past) and it can cause platform dependent problems.
If generating a file with the requires is to onerous, I can understand and we can go this route, but I'd prefer if we didn'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.
I'll give that a whirl
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.
Added a new commit: 7dab057
We now generate modules in lib/protoboeuf/google/api.rb
and lib/protoboeuf/google/protobuf.rb
that autoload all of the constants defined in lib/protoboeuf/google/**/*.rb
! Note that they're collapsed by default in the PR diff view because I marked them as autogenerated in .gitattributes
. Big thanks to @rwstauner for helping me update the Rakefile
in a way where I wouldn't embarrass myself.
5e8c636
to
a4ea5b8
Compare
…r generated constants
a4ea5b8
to
7dab057
Compare
Pairing with @nirvdrum , we noticed
require "protoboeuf"
didn't work despite having it in ourGemfile
which led to some confusion (#170). This makesrequire "protoboeuf"
work and auto- and eagerloads some constants for the user.ProtoBoeuf::CodeGen
is nowautoload
ed from the baselib/protoboeuf.rb
ProtoBoeuf::Google
is also nowautoload
ed from the baselib/protoboeuf.rb
Everything inlib/protoboeuf/google/**/*.rb
is eager loaded whenProtoBoeuf::Google
loads. There isn't a clean 1:1 mapping between constants and*.rb
files soautoload
would be fairly tricky. Although this could be a controversial decision, I think this makes things easier to work with. But feedback is welcome.rake well_known_types
now generates modules that autoload all child constants for well known types (eg:ProtoBoeuf::Google::Protobuf
with the help ofProtoBoeuf::AutoloaderGen
!