Sha256: fa75ade143fd178b106d6b3380a8b2caf4fbb545131ac591a37877f12d23b270

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

require 'uri'
require 'swiftype-enterprise/version'

module SwiftypeEnterprise
  module Configuration
    DEFAULT_ENDPOINT = "https://api.swiftype.com/api/v1/"
    DEFAULT_USER_AGENT = "swiftype-enterprise-ruby/#{SwiftypeEnterprise::VERSION}"

    VALID_OPTIONS_KEYS = [
      :access_token,
      :user_agent,
      :endpoint
    ].freeze

    attr_accessor *VALID_OPTIONS_KEYS

    def self.extended(base)
      base.reset
    end

    # Reset configuration to default values.
    def reset
      self.access_token = nil
      self.endpoint = DEFAULT_ENDPOINT
      self.user_agent = DEFAULT_USER_AGENT
      self
    end

    # Yields the SwiftypeEnterprise::Configuration module which can be used to set configuration options.
    #
    # @return self
    def configure
      yield self
      self
    end

    # Return a hash of the configured options.
    def options
      options = {}
      VALID_OPTIONS_KEYS.each{ |k| options[k] = send(k) }
      options
    end

    # setter for endpoint that ensures it always ends in '/'
    def endpoint=(endpoint)
      if endpoint.end_with?('/')
        @endpoint = endpoint
      else
        @endpoint = "#{endpoint}/"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
swiftype-enterprise-2.0.0 lib/swiftype-enterprise/configuration.rb
swiftype-enterprise-1.0.1 lib/swiftype-enterprise/configuration.rb