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

Namespace extension fields #303

Merged
merged 3 commits into from
Mar 18, 2016

Conversation

nerdrew
Copy link
Contributor

@nerdrew nerdrew commented Feb 17, 2016

This PR is branched off #302, so the first commit can be ignored.

cc @embark

@nerdrew nerdrew force-pushed the namespace-extension-fields branch from 2a18b2b to d230acd Compare February 24, 2016 19:26
@nerdrew nerdrew changed the title [WAITING ON #302] Namespace extension fields Namespace extension fields Feb 24, 2016
@nerdrew nerdrew force-pushed the namespace-extension-fields branch from d230acd to 48fb343 Compare February 24, 2016 21:48
@@ -20,7 +20,7 @@ class FieldGenerator < Base
attr_reader :field_options

def applicable_options
@applicable_options ||= field_options.map { |k, v| ":#{k} => #{v}" }
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused by what this is for, same with the one below

Copy link
Contributor

Choose a reason for hiding this comment

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

it's for extension names with a dot in the middle -- wouldn't be valid ruby syntax with :foo.bar so it has to be :"foo.bar"

Copy link
Contributor

Choose a reason for hiding this comment

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

You can't do :.string without ruby complaining, you have to do :".string". Now that we are namespacing options and extensions in general, the names will include .

Copy link
Contributor

Choose a reason for hiding this comment

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

Dang it @zachmargolis beat me while I had typed out my answer but failed to press send for 20 minutes :P

Copy link
Contributor

Choose a reason for hiding this comment

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

My suggestion would be to explicitly use double quotes rather than relying on inspect since it's not totally obvious. Or maybe a comment to clarify?

Sent from my iPhone

On Feb 25, 2016, at 12:44, Zach Margolis notifications@github.com wrote:

In lib/protobuf/generators/field_generator.rb:

@@ -20,7 +20,7 @@ class FieldGenerator < Base
attr_reader :field_options

   def applicable_options
  •    @applicable_options ||= field_options.map { |k, v| ":#{k} => #{v}" }
    
    it's for extension names with a dot in the middle -- wouldn't be valid ruby syntax with :foo.bar so it has to be :"foo.bar"


Reply to this email directly or view it on GitHub.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So:

@applicable_options ||= field_options.map { |k, v| ":\"#{k}\" => #{v}" }

?

Examples:

[1] pry(main)> sym = ".boom.foo".to_sym
=> :".boom.foo"
[2] pry(main)> puts sym.inspect
:".boom.foo"
=> nil
[3] pry(main)> puts %[:"#{sym}"]
:".boom.foo"
=> nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed with a comment.

(Not applicable to proto field names, but inspect is nice: :'boom"'.inspect #=> ":\"boom\\\"\"")

@zanker
Copy link
Contributor

zanker commented Feb 25, 2016

Seems fine, confused by inspect though

@zachmargolis
Copy link
Contributor

So excited for this! Should we do a bigger version bump than a patch since it may be not bavvkwards compat?

@embark
Copy link
Contributor

embark commented Feb 25, 2016

Agreed that it is not currently backwards compatible in this case:

Before:

> ::Example::Message.new[:extension_field]
=> 2.0

After:

> ::Example::Message.new[:extension_field]
=> ArgumentError: invalid field name=:extension_field
> ::Example::Message.new[:".example.Namespaced.extension_field"]
=> 2.0

@nerdrew
Copy link
Contributor Author

nerdrew commented Feb 26, 2016

@embark True. It is not backward compatible. To make it backward compatible, we can store the unnamespaced extension name in the message field store (as both a string and a symbol), but it is getting a little crazy in there.

The field_store would then have the following keys that all refer to the name field: tag, field_name (a symbol), field_name.to_s, unnamespaced field_name, and unnamespaced field_name.to_s.

field_store[1] == field_store[:extension_field] == field_store["extension_field"] == field_store[:".my_package.extension_field"] == field_store[".my_package.extension_field"]

No judgements, but, hmmmm.... yes judgements.

@embark
Copy link
Contributor

embark commented Feb 26, 2016

@zachmargolis or @film42 thoughts on keeping it backwards compatible now with deprecated accessors, or just doing a bigger version bump? It will be so nice to support extensions with the same name in for the same message.

@zachmargolis
Copy link
Contributor

@embark I think that as good software practices, it would be good make a small bump with a deprecation warning and then a big bump with the breaking change? That is sort of what was outlined in in #196: #196 (comment)

@liveh2o
Copy link
Contributor

liveh2o commented Feb 26, 2016

It might be ugly, but a clean upgrade path is how we typically try to roll. We might be approaching time for a major version bump where we can cleanup a lot of the "cruft" that we've accumulated.

@nerdrew nerdrew force-pushed the namespace-extension-fields branch from e431530 to b4e6709 Compare March 3, 2016 19:20
@nerdrew nerdrew force-pushed the namespace-extension-fields branch from b4e6709 to 5ab6bbb Compare March 3, 2016 19:29
@embark embark force-pushed the namespace-extension-fields branch from 5ab6bbb to f52b276 Compare March 8, 2016 20:49
@embark
Copy link
Contributor

embark commented Mar 8, 2016

Hey guys so we updated the branch to be backwards compatible. The specs of the new commit show the new accessors that we allow, basically:
field_store[1] == field_store[:extension_field] == field_store["extension_field"] == field_store[:".my_package.extension_field"] == field_store[".my_package.extension_field"] works

@zachmargolis
Copy link
Contributor

yayyyyyy LGTM 👍 😎 🎉

@liveh2o
Copy link
Contributor

liveh2o commented Mar 9, 2016

One last look, @film42 or @mmmries?

@embark
Copy link
Contributor

embark commented Mar 14, 2016

@film42 @mmmries beginning of the week ping :)

@film42
Copy link
Member

film42 commented Mar 16, 2016

:shipit: 🎉 :shipit: 🎉 :shipit: 🎉 :shipit: 🎉 :shipit: 🎉 :shipit:

film42 added a commit that referenced this pull request Mar 18, 2016
@film42 film42 merged commit 9086be3 into ruby-protobuf:master Mar 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants