Sha256: 63295150c001ba2dbbe7b73341e72e28e4eca3ace9863d9aa5608c94848182fb

Contents?: true

Size: 1.37 KB

Versions: 5

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

require 'singleton'

class Valvat
  ##
  # Configuration options should be set by passing a hash:
  #
  #   Valvat.configure(
  #     uk: true
  #   )
  #
  def self.configure(options)
    Configuration.instance.configure(options) unless options.nil?
  end

  # Read-only access to config
  def self.config
    Configuration.instance
  end

  class Configuration
    include Singleton

    DEFAULTS = {
      # Set to true to always raise error, even on temporary maintenance downtime errors,
      # set to false to suppress all errors and return nil instead
      raise_error: nil,

      # Set options for the http client.
      # These options are directly passed to `Net::HTTP.start`
      http: {}.freeze,

      # Return details hash on lookup instead of boolean
      detail: false,

      # Your own VAT number used on lookup
      requester: nil,

      # Skip local validation on lookup
      skip_local_validation: false,

      # Use lookup via HMRC for VAT numbers from the UK
      # if set to false lookup will always return false for UK VAT numbers
      uk: false
    }.freeze

    def self.initialize
      instance.send(:initialize)
    end

    def [](key)
      @data[key]
    end

    def configure(options)
      @data = @data.merge(Utils.deep_symbolize_keys(options))
    end

    def initialize
      @data = DEFAULTS.clone
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
valvat-1.4.4 lib/valvat/configuration.rb
valvat-1.4.3 lib/valvat/configuration.rb
valvat-1.4.2 lib/valvat/configuration.rb
valvat-1.4.1 lib/valvat/configuration.rb
valvat-1.4.0 lib/valvat/configuration.rb