Class: TypesenseModel::Configuration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



7
8
9
10
11
12
13
14
# File 'lib/typesense_model/configuration.rb', line 7

def initialize
  @api_key = nil
  @host = 'localhost'
  @port = 8108
  @protocol = 'http'
  @connection_timeout_seconds = 5
  @client_mutex = Mutex.new
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



5
6
7
# File 'lib/typesense_model/configuration.rb', line 5

def api_key
  @api_key
end

#connection_timeout_secondsObject

Returns the value of attribute connection_timeout_seconds.



5
6
7
# File 'lib/typesense_model/configuration.rb', line 5

def connection_timeout_seconds
  @connection_timeout_seconds
end

#hostObject

Returns the value of attribute host.



5
6
7
# File 'lib/typesense_model/configuration.rb', line 5

def host
  @host
end

#portObject

Returns the value of attribute port.



5
6
7
# File 'lib/typesense_model/configuration.rb', line 5

def port
  @port
end

#protocolObject

Returns the value of attribute protocol.



5
6
7
# File 'lib/typesense_model/configuration.rb', line 5

def protocol
  @protocol
end

Instance Method Details

#clientObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/typesense_model/configuration.rb', line 16

def client
  return @client if @client

  @client_mutex.synchronize do
    @client ||= Typesense::Client.new(
      api_key: api_key,
      nodes: [{
        host: host,
        port: port,
        protocol: protocol
      }],
      connection_timeout_seconds: connection_timeout_seconds
    )
  end
end