module Knuckles::Stages::Dumper
The dumping process combines de-duplication and actual serialization. For every top level key that is an array all of the children will have uniqueness enforced. For example, if you had rendered a collection of posts that shared the same author, you will only have a single author object serialized. Be aware that the uniqueness check relies on the presence of an `id` key rather than full object comparisons.
Public Instance Methods
call(objects, _options)
click to toggle source
De-duplicate values in all keys and merge them into a single hash. Afterwards the complete hash is serialized using the serializer configured at `Knuckles.serializer`.
@param [Enumerable<Hash>] objects A collection of hashes to be dumped @param [Hash] _options Options aren't used, but are accepted
to maintain a consistent interface
# File lib/knuckles/stages/dumper.rb, line 22 def call(objects, _options) Knuckles.serializer.dump(keys_to_arrays(objects)) end
Private Instance Methods
keys_to_arrays(objects)
click to toggle source
# File lib/knuckles/stages/dumper.rb, line 28 def keys_to_arrays(objects) objects.each do |_, value| if value.is_a?(Array) value.uniq! { |hash| hash["id"] || hash[:id] } end end end