Sha256: 90bfb4aaebac5a64fb67a6474e00e82f12cb96830e356f68be281864d922f420
Contents?: true
Size: 1.07 KB
Versions: 1
Compression:
Stored size: 1.07 KB
Contents
# frozen_string_literal: true require 'attr/gather/aggregators/base' module Attr module Gather module Aggregators # Shallowly merges results # # @api public class ShallowMerge < Base # Initialize a new DeepMerge aggregator # # @param reverse [Boolean] merge results in reverse order # @param merge_input [Boolean] include input in aggregation result # # @api private def initialize(reverse: false, merge_input: true, **) @reverse = reverse @merge_input = merge_input super end def call(input, execution_results) execution_results = execution_results.reverse_each if reverse? initial = merge_input? ? input.dup : {} result = execution_results.reduce(initial) do |memo, res| memo.merge(unwrap_result(res)) end wrap_result(result) end private def reverse? @reverse end def merge_input? @merge_input end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
attr-gather-1.1.1 | lib/attr/gather/aggregators/shallow_merge.rb |