Class: Typesense::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/typesense/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Configuration

Returns a new instance of Configuration.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/typesense/configuration.rb', line 9

def initialize(options = {})
  @nodes = options[:nodes] || []
  @nearest_node = options[:nearest_node]
  @connection_timeout_seconds = options[:connection_timeout_seconds] || options[:timeout_seconds] || 10
  @healthcheck_interval_seconds = options[:healthcheck_interval_seconds] || 15
  @num_retries = options[:num_retries] || (@nodes.length + (@nearest_node.nil? ? 0 : 1)) || 3
  @retry_interval_seconds = options[:retry_interval_seconds] || 0.1
  @api_key = options[:api_key]

  @logger = options[:logger] || Logger.new($stdout)
  @log_level = options[:log_level] || Logger::WARN
  @logger.level = @log_level

  show_deprecation_warnings(options)
  validate!
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



7
8
9
# File 'lib/typesense/configuration.rb', line 7

def api_key
  @api_key
end

#connection_timeout_secondsObject

Returns the value of attribute connection_timeout_seconds.



7
8
9
# File 'lib/typesense/configuration.rb', line 7

def connection_timeout_seconds
  @connection_timeout_seconds
end

#healthcheck_interval_secondsObject

Returns the value of attribute healthcheck_interval_seconds.



7
8
9
# File 'lib/typesense/configuration.rb', line 7

def healthcheck_interval_seconds
  @healthcheck_interval_seconds
end

#log_levelObject

Returns the value of attribute log_level.



7
8
9
# File 'lib/typesense/configuration.rb', line 7

def log_level
  @log_level
end

#loggerObject

Returns the value of attribute logger.



7
8
9
# File 'lib/typesense/configuration.rb', line 7

def logger
  @logger
end

#nearest_nodeObject

Returns the value of attribute nearest_node.



7
8
9
# File 'lib/typesense/configuration.rb', line 7

def nearest_node
  @nearest_node
end

#nodesObject

Returns the value of attribute nodes.



7
8
9
# File 'lib/typesense/configuration.rb', line 7

def nodes
  @nodes
end

#num_retriesObject

Returns the value of attribute num_retries.



7
8
9
# File 'lib/typesense/configuration.rb', line 7

def num_retries
  @num_retries
end

#retry_interval_secondsObject

Returns the value of attribute retry_interval_seconds.



7
8
9
# File 'lib/typesense/configuration.rb', line 7

def retry_interval_seconds
  @retry_interval_seconds
end

Instance Method Details

#validate!Object



26
27
28
29
30
31
32
33
34
# File 'lib/typesense/configuration.rb', line 26

def validate!
  if @nodes.nil? ||
     @nodes.empty? ||
     @nodes.any? { |node| node_missing_parameters?(node) }
    raise Error::MissingConfiguration, 'Missing required configuration. Ensure that nodes[][:protocol], nodes[][:host] and nodes[][:port] are set.'
  end

  raise Error::MissingConfiguration, 'Missing required configuration. Ensure that api_key is set.' if @api_key.nil?
end