Add CacheCrispies::Base#transform_keys method#55
Add CacheCrispies::Base#transform_keys method#55wujibear wants to merge 2 commits intocodenoble:mainfrom
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? |
adamcrown
left a comment
There was a problem hiding this comment.
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.
Why is the || attrib needed here?
There was a problem hiding this comment.
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.
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.
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:
{ "id": "123", "createdAt": "date", "someThing": "here" }I then have all my serializers inherit from this one and now all my keys will be transformed to lower camelcase
See: #52