Class: SunspotConnector::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/sunspot_connector/connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(config = Config.new) ⇒ Connection

Returns a new instance of Connection.

Raises:

  • (ArgumentError)


6
7
8
9
# File 'lib/sunspot_connector/connection.rb', line 6

def initialize(config = Config.new)
  raise ArgumentError, 'expected SunspotConnector::Config' unless config.is_a?(Config)
  @config = config
end

Instance Method Details

#build_connectionObject



15
16
17
18
19
20
21
22
# File 'lib/sunspot_connector/connection.rb', line 15

def build_connection
  Faraday.new do |conn|
    conn.headers = {
      'Keep-Alive' => 'timeout=10'
    }.merge(@config.headers)
    conn.adapter @config.adapter if @config.adapter
  end
end

#connect(opts = {}) ⇒ Object



11
12
13
# File 'lib/sunspot_connector/connection.rb', line 11

def connect(opts = {})
  RSolr::Client.new(build_connection, opts)
end