Convert dot-delimited package name to nested modules
Closed this issue · 7 comments
I'm working on a big project with lots of proto messages and would like to organize them into modules/directories. I would like this:
package my_company.component_one;
message MapleBaconDonut {
...
}
to compile to this:
module MyCompany
module ComponentOne
class MapleBaconDonut < ::ProtocolBuffers::Message
...
end
end
end
Reasonable?
very reasonable, in fact based on the .proto language spec i'd call it a bug that ruby-protocol-buffers doesn't already do this.
+1
I forked and am working up a pull request for this and the other issues I entered. Or are you working on these, Brian?
The runtime works great. My troubles are just with getting the compiler to deal with how I want to structure my classes within modules and use imports.
I want to verify that what I'm thinking is good Ruby naming convention. For example, in your tests you currently have this in a simple.proto file:
package simple;
message Test1 {
optional string test_field = 1;
};
Whereas, i was assuming the proto file would be named after the top level message in it. So in this case there would be simple/test1.proto where simple is a dir corresponding to the module.
I know this is just naming stuff, but I've not found much about protocol buffers and Ruby modules beyond really simple examples, and I wanted to verify before I start putting dirs in the tests in my fork.
No I haven't begun any work on these filed issues yet. I think you're talking more specifically about issue #10, not this issue -- however, what you're asking for isn't really feasible. You have to remember that Protocol Buffers is a cross-language system and a large portion of the people who will use this library are also using the exact same .proto files to generate C++ or Java code. So we can't make the same sort of assumptions about file system layout and naming conventions as a purely ruby-focused library could do.
Check out the protocol buffers language spec if you want to learn more about how the other languages generate code and implement their runtimes. But I don't see how this library can safely make any assumptions about how packages map to directories or how a .proto filename corresponds to what is in the file, it's simply outside the scope of the language spec.
I'm not even sure how we can add require/load statements to the generated .pb.rb
files, since we can't know where the generated files are placed on disk, but I'm open to suggestions.
I thought of a better way to summarize, sorry:
Any way that we can make things easier for developers who follow an established naming convention is great. But it has to be purely optional, and we have to automatically fall back to the more general support when the convention is not followed.
awesome, thanks for helping out rob