Sha256: 2a88f7c19a4a398c3a4ce4d876c975ff597265488afa5689acb5a23959a2d63c

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

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

    DEFAULT_URI = (ENV['SENTINEL_API_URI'] || 'http://localhost:3000/reports').freeze
    DEFAULT_METHOD = (ENV['SENTINEL_API_METHOD'] || 'post').freeze
    DEFAULT_PROJECT_NAME = "Sentinel Project".freeze

    def initialize
      @uri = DEFAULT_URI
      @method = DEFAULT_METHOD
      @project_name = DEFAULT_PROJECT_NAME
    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

1 entries across 1 versions & 1 rubygems

Version Path
logkeeper_api-0.0.8 lib/sentinel_api/configuration.rb