Sha256: 240980486b7e97dd11143d774de12da659ec956ac044de89fa0a0a9e7bb17506

Contents?: true

Size: 1.41 KB

Versions: 4

Compression:

Stored size: 1.41 KB

Contents

require 'ostruct'
require 'active_support/core_ext/string'

module Kcl
  class Configuration < OpenStruct
    def initialize config = {}
      super default_config.merge config
    end

    def to_properties
      check_config

      to_h.map do |key, value|
        "#{make_prop_key key}=#{value}"
      end.join "\n"
    end

    private

    def check_config
      required_propertie_keys.each do |required_key|
        fail "#{required_key} is required" unless to_h[required_key].present?
      end
    end

    def make_prop_key key
      default_key_map.fetch key, key.to_s.camelize(:lower)
    end

    def application_name
      ENV['APP_NAME']
    end

    def executable_name
      caller.each do |trace|
        matched = trace.match(/\A(?<file>.+)\:\d+\:in.*<main>.*\Z/)

        return matched[:file] if matched
      end
    end

    def processing_language
      "ruby/#{RUBY_VERSION}"
    end

    def default_config
      @default_config ||= {
        executable_name: executable_name,
        application_name: application_name,
        processing_language: processing_language,
        aws_credentials_provider: 'DefaultAWSCredentialsProviderChain',
        initial_position_in_stream: 'TRIM_HORIZON'
      }
    end

    def required_propertie_keys
      default_config.keys.concat [:stream_name]
    end

    def default_key_map
      {
        aws_credentials_provider: 'AWSCredentialsProvider'
      }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
amazon-kinesis-client-ruby-1.0.1 lib/kcl/configuration.rb
amazon-kinesis-client-ruby-1.0.0 lib/kcl/configuration.rb
amazon-kinesis-client-ruby-0.0.3 lib/kcl/configuration.rb
amazon-kinesis-client-ruby-0.0.1 lib/kcl/configuration.rb