Sha256: b9f79f11afd40eb77d58111efef1622c23feb001b90977fc9ebabc4ff742b27b

Contents?: true

Size: 853 Bytes

Versions: 2

Compression:

Stored size: 853 Bytes

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
        #
        # @api private
        def initialize(reverse: false, **)
          @reverse = reverse
          super
        end

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

          result = items.reduce(input.dup) do |memo, res|
            memo.merge(unwrap_result(res))
          end

          wrap_result(result)
        end

        private

        def reverse?
          @reverse
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
attr-gather-1.1.0 lib/attr/gather/aggregators/shallow_merge.rb
attr-gather-1.0.0 lib/attr/gather/aggregators/shallow_merge.rb