Sha256: 842fcf52e2194edf6c3786235e69ca815b900e82d2d3678f4ee9e42c6b671ae7

Contents?: true

Size: 994 Bytes

Versions: 12

Compression:

Stored size: 994 Bytes

Contents

# frozen_string_literal: true

require_relative '../base'

module Fusuma
  module Plugin
    module Filters
      # Filter to keep/discard events from input plugin
      class Filter < Base
        # Filter input event
        # @param event [Event]
        # @return [Event] when keeping event
        # @return [NilClass] when discarding record
        def filter(event)
          return event if event.tag !~ /#{source}/

          return event if keep?(event.record)

          nil
        end

        # @abstract override `#keep?` to implement
        # @param record [String]
        # @return [True]  when keeping record
        # @return [False] when discarding record
        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

12 entries across 12 versions & 1 rubygems

Version Path
fusuma-2.4.1 lib/fusuma/plugin/filters/filter.rb
fusuma-2.4.0 lib/fusuma/plugin/filters/filter.rb
fusuma-2.3.0 lib/fusuma/plugin/filters/filter.rb
fusuma-2.2.0 lib/fusuma/plugin/filters/filter.rb
fusuma-2.1.0 lib/fusuma/plugin/filters/filter.rb
fusuma-2.0.5 lib/fusuma/plugin/filters/filter.rb
fusuma-2.0.4 lib/fusuma/plugin/filters/filter.rb
fusuma-2.0.3 lib/fusuma/plugin/filters/filter.rb
fusuma-2.0.2 lib/fusuma/plugin/filters/filter.rb
fusuma-2.0.1 lib/fusuma/plugin/filters/filter.rb
fusuma-2.0.0 lib/fusuma/plugin/filters/filter.rb
fusuma-2.0.0.pre2 lib/fusuma/plugin/filters/filter.rb