Class: Valvat::Configuration

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/valvat/configuration.rb

Constant Summary collapse

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
  # HMRC options:
  # :client_id and :client_secret     API credentials for OAuth 2.0 Authentication
  # :sandbox                          Use sandboxed instead of production API (defaults to false)
  # See more details https://developer.service.hmrc.gov.uk/api-documentation/docs/development-practices
  #
  uk: false,

  # Rate limit for Lookup and HMRC authentication requests
  rate_limit: 5
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



72
73
74
# File 'lib/valvat/configuration.rb', line 72

def initialize
  @data = DEFAULTS.clone
end

Class Method Details

.initializeObject



56
57
58
# File 'lib/valvat/configuration.rb', line 56

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

Instance Method Details

#[](key) ⇒ Object



60
61
62
# File 'lib/valvat/configuration.rb', line 60

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

#configure(options) ⇒ Object



68
69
70
# File 'lib/valvat/configuration.rb', line 68

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

#dig(*keys) ⇒ Object



64
65
66
# File 'lib/valvat/configuration.rb', line 64

def dig(*keys)
  @data.dig(*keys)
end