Class: Attr::Gather::Aggregators::DeepMerge
- Defined in:
- lib/attr/gather/aggregators/deep_merge.rb
Overview
Deep merges result hashes
Instance Method Summary collapse
- #call(input, execution_results) ⇒ Object
-
#initialize(reverse: false, merge_input: true, array_strategy: :concat) ⇒ DeepMerge
constructor
private
Initialize a new DeepMerge aggregator.
Constructor Details
#initialize(reverse: false, merge_input: true, array_strategy: :concat) ⇒ DeepMerge
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
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/attr/gather/aggregators/deep_merge.rb', line 19 def initialize(reverse: false, merge_input: true, array_strategy: :concat, **) unless ARRAY_STRATEGY.include?(array_strategy) raise ArgumentError, 'array_strategy must be one of: :concat, :overwrite' end @reverse = reverse @merge_input = merge_input @array_strategy = array_strategy super end |
Instance Method Details
#call(input, execution_results) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/attr/gather/aggregators/deep_merge.rb', line 31 def call(input, execution_results) execution_results = execution_results.reverse_each if reverse? execution_results.reduce(@merge_input ? input : EMPTY_HASH) do |memo, res| deep_merge(memo, unwrap_result(res)) end end |