Module: SwiftypeEnterprise::Configuration

Included in:
SwiftypeEnterprise
Defined in:
lib/swiftype-enterprise/configuration.rb

Constant Summary collapse

DEFAULT_ENDPOINT =
"http://localhost:3002/api/v1/"
DEFAULT_USER_AGENT =
"swiftype-enterprise-ruby/#{SwiftypeEnterprise::VERSION}"
VALID_OPTIONS_KEYS =
[
  :access_token,
  :user_agent,
  :endpoint
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



17
18
19
# File 'lib/swiftype-enterprise/configuration.rb', line 17

def self.extended(base)
  base.reset
end

Instance Method Details

#configure {|_self| ... } ⇒ Object

Yields the SwiftypeEnterprise::Configuration module which can be used to set configuration options.

Yields:

  • (_self)

Yield Parameters:

Returns:

  • self



32
33
34
35
# File 'lib/swiftype-enterprise/configuration.rb', line 32

def configure
  yield self
  self
end

#endpoint=(endpoint) ⇒ Object

setter for endpoint that ensures it always ends in ‘/’



45
46
47
48
49
50
51
# File 'lib/swiftype-enterprise/configuration.rb', line 45

def endpoint=(endpoint)
  if endpoint.end_with?('/')
    @endpoint = endpoint
  else
    @endpoint = "#{endpoint}/"
  end
end

#optionsObject

Return a hash of the configured options.



38
39
40
41
42
# File 'lib/swiftype-enterprise/configuration.rb', line 38

def options
  options = {}
  VALID_OPTIONS_KEYS.each{ |k| options[k] = send(k) }
  options
end

#resetObject

Reset configuration to default values.



22
23
24
25
26
27
# File 'lib/swiftype-enterprise/configuration.rb', line 22

def reset
  self.access_token = nil
  self.endpoint = DEFAULT_ENDPOINT
  self.user_agent = DEFAULT_USER_AGENT
  self
end