-
Notifications
You must be signed in to change notification settings - Fork 21
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
Serialize from hash #96
Comments
@glaucocustodio, thank you, I guess that's a good feature to have, I would be glad accepting a PR. The only thing to keep in mind is that we don't want to pollute the hash.keys.length == schema.keys.length
hash.keys.map(&:to_sym).sort == schema.keys.sort And we will also need tests covering different cases, apparently. |
Using my wrapper for hash, I just needed to change the def check_for_ar(schema, instance, key, value)
if ar_collection?(instance, key)
construct_collection(schema, instance, key, value)
else
ins = if instance.respond_to?(key)
instance.send(key)
elsif instance.is_a?(Hash)
instance[key]
else
instance
end
call(value, ins)
end
end |
You see, I don't think that 4 if statements in one method is a good thing at all. And the semantics are broken here - why would we check for active record if we are just serializing a hash |
You are right, this code is not very good. I need to take some time to create the HashBuilder. |
Closing this due to #106 |
Suppose I have:
I can't serialize passing a hash (because the gem expect methods):
Do you plan add support for hash? I've created the thin wrapper below and it works:
With a simple piece of code like that we can open a bunch of new possibilities.
The text was updated successfully, but these errors were encountered: