Sha256: ded42541555fba56d3c8bd932f40edfa0c65d30f3e4d8e9103ca8a6113143734

Contents?: true

Size: 1.13 KB

Versions: 11

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require 'singleton'

class LHC::Config
  include Singleton

  attr_accessor :scrubs

  def initialize
    @endpoints = {}
    @placeholders = {}
    @scrubs = default_scrubs
  end

  def endpoint(name, url, options = {})
    name = name.to_sym
    raise 'Endpoint already exists for that name' if @endpoints[name]

    @endpoints[name] = LHC::Endpoint.new(url, options)
  end

  def endpoints
    @endpoints.dup
  end

  def placeholder(name, value)
    name = name.to_sym
    raise 'Placeholder already exists for that name' if @placeholders[name]

    @placeholders[name] = value
  end

  def placeholders
    @placeholders.dup
  end

  def interceptors
    (@interceptors || []).dup
  end

  def interceptors=(interceptors)
    raise 'Default interceptors already set and can only be set once' if @interceptors

    @interceptors = interceptors
  end

  def default_scrubs
    {
      auth: [:bearer, :basic],
      params: [],
      headers: [],
      body: ['password', 'password_confirmation']
    }
  end

  def reset
    @endpoints = {}
    @placeholders = {}
    @interceptors = nil
    @scrubs = default_scrubs
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
lhc-15.2.1 lib/lhc/config.rb
lhc-15.2.0 lib/lhc/config.rb
lhc-15.1.3 lib/lhc/config.rb
lhc-15.1.2 lib/lhc/config.rb
lhc-15.1.1 lib/lhc/config.rb
lhc-15.1.0 lib/lhc/config.rb
lhc-16.0.0.pre.pro2162.2 lib/lhc/config.rb
lhc-16.0.0.pre.pro2162 lib/lhc/config.rb
lhc-15.0.1 lib/lhc/config.rb
lhc-15.0.0 lib/lhc/config.rb
lhc-13.4.0.pre.pro1766.1 lib/lhc/config.rb