Sha256: d958f22936a4f1b045c857cb9e297aa0a8eee306adf41930724fe5a9e345cdf3

Contents?: true

Size: 1.13 KB

Versions: 12

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require_relative '../base'

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)
          return event if event.tag != source

          new_record = parse_record(event.record)
          return event if new_record.nil?

          event.record = new_record
          event.tag = tag
          event
        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
          @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

12 entries across 12 versions & 1 rubygems

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