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

WIP: Support field renaming #19

Closed
wants to merge 1 commit into from
Closed

WIP: Support field renaming #19

wants to merge 1 commit into from

Conversation

tjwp
Copy link
Collaborator

@tjwp tjwp commented Aug 22, 2016

I did some work on allowing schema fields to be renamed in the generated model. This would to be to address Issue #17, but may also help if a schema field name conflicts with another method on an Avromatic model.

If this goes forward, I think that "aliases" should be changed to something like "renames" to avoid confusion with aliases in Avro schema names, and to make it clear the original field name is not available on the model.

It's also unclear what is the most natural way to configure this. In this code, the configuration is based on the field names within a schema, including nested fields. Would it be better to configure renaming scoped by the record type name instead of the field name within a record?

There still some work to do on validating the renames/aliases.

These changes also raise the question of whether there are too many methods defined on model instances by Avromatic. For example, there is a set of methods delegated to the class. Should these instead be called directly on the class to avoid field conflicts, or should a prefix be used to reduce the chance of a name collision. This should probably be handled separately.

I think the changes to Avromatic::Model::Attributes here also suggest that this module should be refactored. Instead of passing around information about the field/attribute currently being processed we could introduce an AttributeBuilder class that holds the context and responds to methods providing what should be generated for that attribute.

Prime: @jturkel

```ruby
Avromatic::Model.model(
schema_name: 'reserved_names',
aliases: { attributes: :my_attributes }
Copy link
Member

Choose a reason for hiding this comment

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

I agree aliases is a bit misleading. renames or mappings work for me.

@tjwp
Copy link
Collaborator Author

tjwp commented Sep 14, 2016

Putting this on hold for now.

@tjwp tjwp closed this Sep 14, 2016
@jturkel jturkel deleted the feature/reserved-names branch October 1, 2018 14:46
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.

2 participants