Sha256: 88af06ac7806d6978fa874fda503bd840b4d2ab4001e202761f59e71572b655c

Contents?: true

Size: 1.56 KB

Versions: 28

Compression:

Stored size: 1.56 KB

Contents

# encoding: utf-8

module LogStash module PluginMixins module JdbcStreaming
  class ParameterHandler

    def self.build_parameter_handler(given_value)
      # does it really make sense to deal with normal parameters differently?
      handler = FieldParameter.new(given_value)
      return handler unless given_value.is_a?(String)

      first_percent_curly = given_value.index("%{")
      if first_percent_curly && given_value.index("}", first_percent_curly)
        return InterpolatedParameter.new(given_value)
      end

      handler
    end

    def self.build_bind_value_handler(given_value)
      handler = ConstantParameter.new(given_value)

      return handler unless given_value.is_a?(String) # allow non String constants

      first_percent_curly = given_value.index("%{")
      if first_percent_curly && given_value.index("}", first_percent_curly)
        return InterpolatedParameter.new(given_value)
      end

      if given_value =~ /\A(\s*\[[^\]]+\]\s*)*\z/
        return FieldParameter.new(given_value)
      end

      handler
    end

    attr_reader :given_value

    def initialize(given_value)
      @given_value = given_value
    end

    def extract_from(event)
      # override in subclass
    end
  end

  class InterpolatedParameter < ParameterHandler
    def extract_from(event)
      event.sprintf(@given_value)
    end
  end

  class FieldParameter < ParameterHandler
    def extract_from(event)
      event.get(@given_value)
    end
  end

  class ConstantParameter < ParameterHandler
    def extract_from(event)
      @given_value
    end
  end
end end end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
logstash-integration-jdbc-5.5.1 lib/logstash/plugin_mixins/jdbc_streaming/parameter_handler.rb
logstash-integration-jdbc-5.5.0 lib/logstash/plugin_mixins/jdbc_streaming/parameter_handler.rb
logstash-integration-jdbc-5.4.9 lib/logstash/plugin_mixins/jdbc_streaming/parameter_handler.rb
logstash-integration-jdbc-5.4.8 lib/logstash/plugin_mixins/jdbc_streaming/parameter_handler.rb
logstash-integration-jdbc-5.4.7 lib/logstash/plugin_mixins/jdbc_streaming/parameter_handler.rb
logstash-integration-jdbc-5.4.6 lib/logstash/plugin_mixins/jdbc_streaming/parameter_handler.rb
logstash-integration-jdbc-5.4.5 lib/logstash/plugin_mixins/jdbc_streaming/parameter_handler.rb
logstash-integration-jdbc-5.4.4 lib/logstash/plugin_mixins/jdbc_streaming/parameter_handler.rb
logstash-integration-jdbc-5.4.3 lib/logstash/plugin_mixins/jdbc_streaming/parameter_handler.rb
logstash-integration-jdbc-5.4.2 lib/logstash/plugin_mixins/jdbc_streaming/parameter_handler.rb
logstash-integration-jdbc-5.4.1 lib/logstash/plugin_mixins/jdbc_streaming/parameter_handler.rb
logstash-integration-jdbc-5.4.0 lib/logstash/plugin_mixins/jdbc_streaming/parameter_handler.rb
logstash-integration-jdbc-5.3.0 lib/logstash/plugin_mixins/jdbc_streaming/parameter_handler.rb
logstash-integration-jdbc-5.2.6 lib/logstash/plugin_mixins/jdbc_streaming/parameter_handler.rb
logstash-integration-jdbc-5.2.5 lib/logstash/plugin_mixins/jdbc_streaming/parameter_handler.rb
logstash-integration-jdbc-5.2.4 lib/logstash/plugin_mixins/jdbc_streaming/parameter_handler.rb
logstash-integration-jdbc-5.2.3 lib/logstash/plugin_mixins/jdbc_streaming/parameter_handler.rb
logstash-integration-jdbc-5.2.2 lib/logstash/plugin_mixins/jdbc_streaming/parameter_handler.rb
logstash-integration-jdbc-5.2.1 lib/logstash/plugin_mixins/jdbc_streaming/parameter_handler.rb
logstash-integration-jdbc-5.2.0 lib/logstash/plugin_mixins/jdbc_streaming/parameter_handler.rb