Sha256: 1b0d9316fd10e50139ec12b648e8c173cf5d61d6e7abea61da12118f3ba7a22c

Contents?: true

Size: 1.99 KB

Versions: 29

Compression:

Stored size: 1.99 KB

Contents

require 'faraday'
require File.expand_path('../version', __FILE__)

module AvaTax
  module Configuration

    VALID_OPTIONS_KEYS = [
      :app_name,
      :app_version,
      :machine_name,
      :environment,
      :endpoint,
      :user_agent,
      :username,
      :password,
      :connection_options,
      :logger,
      :custom_logger,
      :custom_logger_options,
      :proxy,
      :faraday_response,
      :response_big_decimal_conversion
    ].freeze

    DEFAULT_APP_NAME = nil
    DEFAULT_APP_VERSION = nil
    DEFAULT_MACHINE_NAME = nil
    DEFAULT_ENDPOINT = 'https://rest.avatax.com'
    DEFAULT_USER_AGENT = "AvaTax Ruby Gem #{AvaTax::VERSION}".freeze
    DEFAULT_USERNAME = nil
    DEFAULT_PASSWORD = nil
    DEFAULT_CONNECTION_OPTIONS = {}
    DEFAULT_LOGGER = false
    DEFAULT_CUSTOM_LOGGER = nil
    DEFAULT_CUSTOM_LOGGER_OPTIONS = {}
    DEFAULT_PROXY = nil
    DEFAULT_FARADAY_RESPONSE = false
    DEFAULT_RESPONSE_BIG_DECIMAL_CONVERSION = false

    attr_accessor *VALID_OPTIONS_KEYS

    # Reset config values when extended
    def self.extended(base)
      base.reset
    end

    # Allow configuration options to be set in a block
    def configure
      yield self
    end

    def options
      VALID_OPTIONS_KEYS.inject({}) do |option, key|
        option.merge!(key => send(key))
      end
    end

    def reset
      self.app_name = DEFAULT_APP_NAME
      self.app_version = DEFAULT_APP_VERSION
      self.machine_name = DEFAULT_MACHINE_NAME
      self.endpoint = DEFAULT_ENDPOINT
      self.user_agent = DEFAULT_USER_AGENT
      self.username = DEFAULT_USERNAME
      self.password = DEFAULT_PASSWORD
      self.connection_options = DEFAULT_CONNECTION_OPTIONS
      self.logger = DEFAULT_LOGGER
      self.custom_logger = DEFAULT_CUSTOM_LOGGER
      self.custom_logger_options = DEFAULT_CUSTOM_LOGGER_OPTIONS
      self.proxy = DEFAULT_PROXY
      self.faraday_response = DEFAULT_FARADAY_RESPONSE
      self.response_big_decimal_conversion = DEFAULT_RESPONSE_BIG_DECIMAL_CONVERSION
    end

  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
avatax-20.12.1 lib/avatax/configuration.rb
avatax-20.9.0 lib/avatax/configuration.rb
avatax-20.7.1 lib/avatax/configuration.rb
avatax-20.7.0 lib/avatax/configuration.rb
avatax-20.6.0 lib/avatax/configuration.rb
avatax-20.5.0 lib/avatax/configuration.rb
avatax-20.1.0 lib/avatax/configuration.rb
avatax-19.12.1 lib/avatax/configuration.rb
avatax-19.12.0 lib/avatax/configuration.rb
avatax-19.11.1 lib/avatax/configuration.rb
avatax-19.10.0 lib/avatax/configuration.rb
avatax-19.9.1 lib/avatax/configuration.rb
avatax-19.9.0 lib/avatax/configuration.rb
avatax-19.8.0 lib/avatax/configuration.rb
avatax-19.7.0 lib/avatax/configuration.rb
avatax-19.6.0 lib/avatax/configuration.rb
avatax-19.5.0 lib/avatax/configuration.rb
avatax-19.4.0 lib/avatax/configuration.rb
avatax-19.3.0 lib/avatax/configuration.rb
avatax-19.2.0 lib/avatax/configuration.rb