Sha256: da2ca9aae7d6e434b05fca8371ebfd60ee0802c2e9548f5e7e568aa01e55d4a9

Contents?: true

Size: 926 Bytes

Versions: 3

Compression:

Stored size: 926 Bytes

Contents

require 'logger'
module SentinelApi
  class Configuration
    attr_accessor :uri
    attr_accessor :level
    attr_accessor :method

    DEFAULT_URI = (ENV['sentinel_uri'] || 'http://localhost:3000/reports').freeze
    DEFAULT_METHOD = (ENV['sentinel_method'] || 'post').freeze

    def initialize
      @uri = DEFAULT_URI
      @method = DEFAULT_METHOD
    end

    def merge(options)
      new_configuration = clone
      new_configuration.merge!(options)

      new_configuration
    end

    def merge!(options)
      options.each do |name, value|
        variable_name = "@#{name}"
        next unless instance_variable_defined?(variable_name)

        instance_variable_set(variable_name, value)
      end

      self
    end

    def default_logger
      @default_logger ||= defined?(::Rails) ? ::Rails.logger : ::Logger.new(STDERR)
    end

    def use_ssl?
      uri.match(/^https:/) ? true : false
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
logkeeper_api-0.0.4 lib/sentinel_api/configuration.rb
logkeeper_api-0.0.3 lib/sentinel_api/configuration.rb
logkeeper_api-0.0.2 lib/sentinel_api/configuration.rb