Sha256: aba76ee157912b6cd30092fdd1cd14b7221a70968df9450be28a8f328accd6c1

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

module KewegoParty
  module Configuration
    VALID_OPTIONS_KEYS = [
      :api_version,
      :login,
      :password,
      :token,
      :app_token,
      :caching_store,
      :debug_output,
      :user_agent].freeze

    DEFAULT_API_VERSION   = 1
    DEFAULT_LOGIN         = nil
    DEFAULT_PASSWORD      = nil
    DEFAULT_TOKEN         = nil
    DEFAULT_APP_TOKEN     = nil
    DEFAULT_CACHING_STORE = ::APICache.store
    DEFAULT_DEBUG_OUTPUT  = nil
    DEFAULT_USER_AGENT    = "Kewego Ruby Gem #{KewegoParty::VERSION}".freeze

    attr_accessor(*VALID_OPTIONS_KEYS)

    def self.extended(base)
      base.reset
    end

    def configure
      yield self
    end

    def options
      VALID_OPTIONS_KEYS.inject({}){|o,k| o.merge!(k => send(k)) }
    end

    def reset
      self.api_version  = DEFAULT_API_VERSION
      self.login        = DEFAULT_LOGIN
      self.password     = DEFAULT_PASSWORD
      self.token        = DEFAULT_TOKEN
      self.app_token    = DEFAULT_APP_TOKEN
      self.debug_output = DEFAULT_DEBUG_OUTPUT
      self.user_agent   = DEFAULT_USER_AGENT

      ::APICache.send(:remove_instance_variable, :@store)
      self.caching_store  = ::APICache.store
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kewego_party-0.0.1 lib/kewego_party/configuration.rb