Other-fields consumtion
Closed this issue · 3 comments
It would be great if algebrick could be used for defining the data comming from external services over REST and others.
Usually, one doesn't care about all the data that come from the REST, and it would cause more harm than benefits to try doing that. The idea is to define only the fields
that we care about in our code-base and don't care about the rest that much.
Let's say, I get this hash from the REST:
p = {"person": {"name":"Petr", "created_at":"2013-12-28"}}
I care only about the name, so instead of having to define all the fields that might occur (and breaking immediately, when something new is added), I want to ignore the rest of store that in some additional field:
Person = Algebrick.type do
fields name: "Petr"
ignore_other_fields
end
or
Person = Algebrick.type do
fields name: "Petr"
store_other_fields :others
end
person = Person[p]
person[:name] # => "Petr"
person[:others][:created_at] # => "2013-12-28"
Maybe, this could be an addition to from_hash
method, as it seems to me as a way to go to load arbitrary hashes as Algebrick types (some work done that direction in #4)
Related to #2. #2 (comment) also applies here.