Sha256: 61a0bf2e648759ea00bb8f8f1938a637fec12c259ca57c767a90b8d383dafcf6

Contents?: true

Size: 1.59 KB

Versions: 8

Compression:

Stored size: 1.59 KB

Contents

module Dirigible
  module Configuration
    VALID_OPTION_KEYS = [
      :app_key,
      :master_secret,
      :endpoint,
      :http_adapter,
      :proxy,
      :user_agent
    ]

    # By default, don't set app key.
    DEFAULT_APP_KEY = nil.freeze

    # By default, don't set the master secret.
    DEFAULT_MASTER_SECRET = nil.freeze

    # The endpoint that will be used to authorize a user if none is set.
    DEFAULT_ENDPOINT = 'https://go.urbanairship.com/api'.freeze

    # The Faraday HTTP adapter to be used.
    DEFAULT_HTTP_ADAPTER = Faraday.default_adapter

    # By default, don't set a proxy server.
    DEFAULT_PROXY = nil.freeze

    # The user agent that will be sent to the API endpoint if none is set.
    DEFAULT_USER_AGENT = "dirigible gem v#{Dirigible::VERSION}"

    # @private
    attr_accessor(*VALID_OPTION_KEYS)

    # When this module is extended, set all configuration options to their
    # default values.
    def self.extended(base)
      base.reset
    end

    # Convenience method to allow configuration options to be set in a
    # block.
    def configure
      yield self
    end

    # Create a hash of options and their values.
    def options
      VALID_OPTION_KEYS.inject({}) do |option, key|
        option.merge!(key => send(key))
      end
    end

    # Reset all configuration options to default.
    def reset
      self.app_key = DEFAULT_APP_KEY
      self.master_secret = DEFAULT_MASTER_SECRET
      self.endpoint = DEFAULT_ENDPOINT
      self.http_adapter = DEFAULT_HTTP_ADAPTER
      self.proxy = DEFAULT_PROXY
      self.user_agent = DEFAULT_USER_AGENT
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
dirigible-1.1.3 lib/dirigible/configuration.rb
dirigible-1.1.2 lib/dirigible/configuration.rb
dirigible-1.1.1 lib/dirigible/configuration.rb
dirigible-1.1.0 lib/dirigible/configuration.rb
dirigible-1.0.4 lib/dirigible/configuration.rb
dirigible-1.0.3 lib/dirigible/configuration.rb
dirigible-0.0.2 lib/dirigible/configuration.rb
dirigible-0.0.1 lib/dirigible/configuration.rb