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

feature: extract! api for getting attributes from object #32

Merged

Conversation

kortirso
Copy link
Contributor

discussed in #30

@jho406
Copy link
Contributor

jho406 commented Jul 30, 2024

This is a great add for users coming from jbuilder. A bit of parity helps.

json.extract! user, :id, :email, :name

There is just one edge case:

json.extract! user, :id, :email, :full_name

When the attribute is full_name, but as props_template doesn't autocamelize keys, a dev expecting fullName, actually gets full_name. What are your thoughts on this syntax to allow for manual setting of they key:

json.extract! user, :id, :email, [:full_name, :fullName], :city, [:phone_number, :phoneNumber], :country

@kortirso
Copy link
Contributor Author

kortirso commented Jul 31, 2024

When the attribute is full_name, but as props_template doesn't autocamelize keys, a dev expecting fullName, actually gets full_name. What are your thoughts on this syntax to allow for manual setting of they key:

json.extract! user, :id, :email, [:full_name, :fullName], :city, [:phone_number, :phoneNumber], :country

I thought about passing block if key needs to be transformed, but this is better

@jho406 jho406 self-requested a review August 2, 2024 18:33
@jho406
Copy link
Contributor

jho406 commented Aug 2, 2024

Looks great! Thanks @kortirso !

@jho406 jho406 merged commit 113e163 into thoughtbot:main Aug 2, 2024
12 checks passed
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