ReportSerializer = Serial::Serializer.new do |h, report|
h.attribute(:foo, "bar")
end
FancyReportSerializer = Serial::Serializer.new do |h, report|
h.merge(report, &ReportSerializer)
h.attribute(:quox, "monkey")
end
The result of FancyReportSerializer would then look like this:
{ "foo": "bar", "quox": "monkey" }
That is, it does not introduce a new level of nesting. There should probably be an equivalent merge! method if #3 is merged.
Also, it no block is passed to merge then the first parameter is assumed to be a hash (or we call #to_h on it), so it is equivalent to Ruby's Hash#merge.
I would like to do something like this:
The result of
FancyReportSerializer
would then look like this:That is, it does not introduce a new level of nesting. There should probably be an equivalent
merge!
method if #3 is merged.Also, it no block is passed to
merge
then the first parameter is assumed to be a hash (or we call#to_h
on it), so it is equivalent to Ruby'sHash#merge
.