Sha256: bead9d9e4c68581902b154e27ad3aac244866080f0af53417aa3f990c7bcf679

Contents?: true

Size: 1.13 KB

Versions: 20

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require_relative '../base.rb'

module Fusuma
  module Plugin
    module Parsers
      # Parser change record and tag in event
      # Inherite this base class
      class Parser < Base
        # Parse Event and convert Record and Tag
        # if `#parse_record` return nil, this method will return original event
        # @param event [Event]
        # @return [Event]
        def parse(event)
          event.tap do |e|
            next if e.tag != source

            new_record = parse_record(e.record)
            next unless new_record

            e.record = new_record
            e.tag = tag
          end
        end

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

        def tag
          self.class.name.split('::').last.underscore
        end

        # parse Record object
        # @param _record [Record]
        # @return [Record, nil]
        def parse_record(_record)
          nil
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
fusuma-2.0.0.pre lib/fusuma/plugin/parsers/parser.rb
fusuma-1.11.1 lib/fusuma/plugin/parsers/parser.rb
fusuma-1.10.2 lib/fusuma/plugin/parsers/parser.rb
fusuma-1.10.1 lib/fusuma/plugin/parsers/parser.rb
fusuma-1.10.0 lib/fusuma/plugin/parsers/parser.rb
fusuma-1.9.0 lib/fusuma/plugin/parsers/parser.rb
fusuma-1.8.0 lib/fusuma/plugin/parsers/parser.rb
fusuma-1.7.0 lib/fusuma/plugin/parsers/parser.rb
fusuma-1.6.0 lib/fusuma/plugin/parsers/parser.rb
fusuma-1.5.0 lib/fusuma/plugin/parsers/parser.rb
fusuma-1.4.1 lib/fusuma/plugin/parsers/parser.rb
fusuma-1.4.0 lib/fusuma/plugin/parsers/parser.rb
fusuma-1.3.3 lib/fusuma/plugin/parsers/parser.rb
fusuma-1.3.2 lib/fusuma/plugin/parsers/parser.rb
fusuma-1.3.1 lib/fusuma/plugin/parsers/parser.rb
fusuma-1.3.0 lib/fusuma/plugin/parsers/parser.rb
fusuma-1.2.1 lib/fusuma/plugin/parsers/parser.rb
fusuma-1.2 lib/fusuma/plugin/parsers/parser.rb
fusuma-1.1 lib/fusuma/plugin/parsers/parser.rb
fusuma-1.0 lib/fusuma/plugin/parsers/parser.rb