Sha256: e08e1863bb52595865fba743fea6bf40185e6a527cb94eaf3f43a828b97e9514

Contents?: true

Size: 864 Bytes

Versions: 1

Compression:

Stored size: 864 Bytes

Contents

# frozen_string_literal: true

require 'attr/gather/filters/noop'

module Attr
  module Gather
    module Aggregators
      # @abstract Subclass and override {#call} to implement
      #   a custom Aggregator class.
      #
      # @!attribute [r] filter
      #   @return [Attr::Gather::Filters::Base] filter for the output data
      class Base
        attr_accessor :filter

        NOOP_FILTER = Filters::Noop.new

        def initialize(**opts)
          @filter = opts.delete(:filter) || NOOP_FILTER
        end

        def with(**opts)
          self.class.new(filter: @filter, **opts)
        end

        def call(_original_input, _results_array)
          raise NotImplementedError
        end

        private

        def unwrap_result(res)
          return res if filter.nil?

          filter.call(res).value
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
attr-gather-1.5.1 lib/attr/gather/aggregators/base.rb