-
Notifications
You must be signed in to change notification settings - Fork 15
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
Add CacheCrispies::Base#transform_keys method #55
base: main
Are you sure you want to change the base?
Conversation
Actually, this only seems to work if I put the method in the serializer that is serializing. |
K. Fixed that, now it checks for parent definitions if no proc or existing instance var is supplied. |
Thanks for the PR. This seems reasonable. I know JS tends to lean towards snake-cased variables and having the JSON the same way can make things simpler with object deconstruction. I would want to see some specs to cover this new functionality before I would merge it though. |
Any other thoughts on method naming, or implementation though? |
Added a spec and docs |
@adamcrown got those specs for you |
@adamcrown Any other thoughts? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is looking really good. I do have a couple small questions though. And apologies for the wait in getting back on this. I should have more time to keep up with this gem now for multiple reasons. So I should be able to come back to this PR soon soon after these comments are addressed.
attrib, | ||
from: from, | ||
transform_key(attrib), | ||
from: from || attrib, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the || attrib
needed here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not great at seeing GH notifications, sorry.
I plan to check out your comments here and address in the next week or two.
I'll need to get back in the code here to recall correctly, but I believe this was meant as an improvement.
It seems like it calls for adding a comment to explain why, lol
```ruby | ||
# app/serializers/base_serializer.rb | ||
class BaseSerializer < CacheCrispies::Base | ||
transform_keys lambda { |key| key.to_s.camelize(:lower) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use a block here rather than a lambda argument?
It just reads a bit better and is a bit more consistent to me to have
transform_keys lambda { |key| key.to_s.camelize(:lower) }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you just repeated the line I have there... accident yes?
You're meaning to have something like this instead?
transform_keys do |key|
key.to_s.camelize(:lower)
end
I was asking about being able to transform keys to something like camelcase and tried this out.
Unsure of your needs for contributions, but let me know what you think of the idea.
With this I can now do the following:
Serialized data will look like:
I then have all my serializers inherit from this one and now all my keys will be transformed to lower camelcase
See: #52