Class: Attr::Gather::Aggregators::ShallowMerge

Inherits:
Base
  • Object
show all
Defined in:
lib/attr/gather/aggregators/shallow_merge.rb

Overview

Shallowly merges results

Instance Method Summary collapse

Constructor Details

#initialize(reverse: false, merge_input: true) ⇒ ShallowMerge

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize a new DeepMerge aggregator

Parameters:

  • reverse (Boolean) (defaults to: false)

    merge results in reverse order

  • merge_input (Boolean) (defaults to: true)

    merge the result with the initial input



18
19
20
21
22
# File 'lib/attr/gather/aggregators/shallow_merge.rb', line 18

def initialize(reverse: false, merge_input: true, **)
  @reverse = reverse
  @merge_input = merge_input
  super
end

Instance Method Details

#call(input, execution_results) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/attr/gather/aggregators/shallow_merge.rb', line 24

def call(input, execution_results)
  execution_results = execution_results.reverse_each if reverse?

  execution_results.reduce(@merge_input ? input : EMPTY_HASH) do |memo, res|
    memo.merge(unwrap_result(res))
  end
end