Class: Typesensual::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/typesensual/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Config

Returns a new instance of Config.

Yields:

  • (_self)

Yield Parameters:



7
8
9
# File 'lib/typesensual/config.rb', line 7

def initialize(&block)
  yield self if block
end

Instance Attribute Details

#api_keyObject



26
27
28
# File 'lib/typesensual/config.rb', line 26

def api_key
  @api_key ||= ENV.fetch('TYPESENSUAL_API_KEY', nil)
end

#clientObject



15
16
17
# File 'lib/typesensual/config.rb', line 15

def client
  @client ||= Typesense::Client.new(connection_options)
end

#envObject



11
12
13
# File 'lib/typesensual/config.rb', line 11

def env
  @env ||= ENV.fetch('TYPESENSUAL_ENV', (defined?(Rails) ? Rails.env : nil))
end

#nodesObject



19
20
21
22
23
24
# File 'lib/typesensual/config.rb', line 19

def nodes
  @nodes ||= ENV['TYPESENSUAL_NODES']&.split(',')&.map do |node|
    node_uri = URI.parse(node)
    { port: node_uri.port, host: node_uri.host, protocol: node_uri.scheme }
  end
end