Sha256: 17b3dc762c37bc06c0f2e66054cb679f004850877cc70c22cca3b3320cb68f0a

Contents?: true

Size: 865 Bytes

Versions: 2

Compression:

Stored size: 865 Bytes

Contents

require "faraday"

module Einvoice
  module Configuration
    VALID_OPTIONS_KEYS = [
      :endpoint,
      :client_id,
      :client_secret,
      :format,
      :endpoint_url
    ].freeze

    DEFAULT_CLIENT_ID = nil
    DEFAULT_CLIENT_SECRET = nil
    DEFAULT_ENDPOINT = "".freeze
    DEFAULT_ENDPOINT_URL = nil
    DEFAULT_FORMAT = ""

    attr_accessor *VALID_OPTIONS_KEYS

    def self.extended(base)
      base.reset
    end

    def configure
      yield self
    end

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

    def reset
      self.client_id     = DEFAULT_CLIENT_ID
      self.client_secret = DEFAULT_CLIENT_SECRET
      self.endpoint      = DEFAULT_ENDPOINT
      self.endpoint_url  = DEFAULT_ENDPOINT_URL
      self.format        = DEFAULT_FORMAT
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
einvoice-1.0.0 lib/einvoice/configuration.rb
einvoice-0.2.8 lib/einvoice/configuration.rb