-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add optional recursive camelization of keys. #428
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
Conversation
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.
Is this needed? ^^^
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.
not really, I can do def self.included
if you want?
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.
You should just include Convertable, there's no need to use that hook
All the things changed in the README file does not belong to this commit. |
Last thing is that I'd execute the convertion of the keys right after the execution of attributes, has_one and has_many so we don't pay the penalty of converting these things on each request. |
lib/active_model/convertable.rb
Outdated
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.
We are discussing about how to treat keys but meanwhile we don't reach a conclusion I wouldn't convert the key back to symbol.
Just leave it as is.
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 don't like the string key return at all, that's my personal opinion and for what it is worth you can take that into consideration when discussing it :) I'll change it for now though I would hate to see AMS get all stringy on me. What would the benefit of that be?
Thanks a lot for your work. |
The problem is it needs to be done for roots as well. Right now we have some logic in |
Regarding when to convert keys: def attributes(*attrs)
@_attributes.concat attrs
attrs.each do |attr|
define_method attr do
object.read_attribute_for_serialization attr
end unless method_defined?(attr)
end
end Won't that I have to keep track of both the converted key and the original key? Is the penalty really worth it? |
Closing in favor of #436 since that seems like a better solution to me. |
This is still sort of a hack. I don't like what I have to do to be able to camelize the root key, I believe a simple setting to switch on would have been nicer but hey it works.
Any suggestions for improvements deeply appreciated.