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

Allow initializing a chain of protos using only a hash in Ruby #3627

Merged
merged 2 commits into from
Sep 21, 2017

Conversation

zanker
Copy link
Contributor

@zanker zanker commented Sep 12, 2017

I saw #3120 also asked for this. We're in the process of trying to migrate people from a pure Ruby proto gem to the Google one, and the requirement to initialize all protos is a blocker. Sounds like there was interest in this, so figured I'd take a stab at implementing it in.

Taking the examples from #3120, this lets you do: MyMessage.new(submessage_field: { foo: 42 })and it will automatically turn the { foo: 42 } into a SubMessage.new(foo: 42).

Since a common scenario is also to be turning JSON into protos (for proto backed JSON APIs), I also changed the initialization to support symbol or string keys to prevent having to do a deep symbolization pass before initializing the protos.

@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

1 similar comment
@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@bazel-io
Copy link

Can one of the admins verify this patch?

@zanker zanker force-pushed the zanker/add-submsg-hash-init branch 7 times, most recently from 4f0d23c to 399ab27 Compare September 18, 2017 21:19
@haberman
Copy link
Member

ok to test

@haberman
Copy link
Member

Looks like this change failed Travis?

@zanker
Copy link
Contributor Author

zanker commented Sep 20, 2017

@haberman Fixed the test that failed. It was one of the compatibility tests, which now fails with RangeError because it's now checking if z is an enum value, whereas previously it would fail with TypeError since it was a string.

Is the fact that the exception changed ok?

Copy link
Member

@haberman haberman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this change. I think the changed exception should be ok. I wouldn't expect anyone to be catching this exception, and the new behavior seems more consistent anyway.

@@ -248,16 +260,26 @@ int Message_initialize_kwarg(VALUE key, VALUE val, VALUE _self) {
Map_merge_into_self(map, val);
} else if (upb_fielddef_label(f) == UPB_LABEL_REPEATED) {
VALUE ary;
VALUE entry;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only used inside the for loop, so please declare it there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@TeBoring
Copy link
Contributor

@zanker could you take a look for #4809?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants