Sha256: 30f97e2d715a6cfec467a3cdbf9ee7a1e6266d9a493adf6c8ba852a247b54ffd

Contents?: true

Size: 925 Bytes

Versions: 3

Compression:

Stored size: 925 Bytes

Contents

# frozen_string_literal: true

require_relative '../base.rb'

module Fusuma
  module Plugin
    # filter class
    module Filters
      # Inherite this base
      class Filter < Base
        # Filter input event
        # @param event [Event]
        # @return [Event, nil]
        def filter(event)
          event.tap do |e|
            next if e.tag != source
            next if keep?(e.record)

            MultiLogger.debug(filtered: e)

            break nil
          end
        end

        # @abstract override `#keep?` to implement
        # @param record [String]
        # @return [True, False]
        def keep?(record)
          true if record
        end

        # Set source for tag from config.yml.
        # DEFAULT_SOURCE is defined in each Filter plugins.
        def source
          @source ||= config_params(:source) || self.class.const_get('DEFAULT_SOURCE')
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fusuma-1.2 lib/fusuma/plugin/filters/filter.rb
fusuma-1.1 lib/fusuma/plugin/filters/filter.rb
fusuma-1.0 lib/fusuma/plugin/filters/filter.rb