Module: Oedipus::Connection::Registry

Included in:
Oedipus
Defined in:
lib/oedipus/connection/registry.rb

Instance Method Summary collapse

Instance Method Details

#connect(options, key = :default) ⇒ Connection

Connect to Sphinx running SphinxQL.

Connections are cached for re-use.

Examples:

c = Oedipus.connect("127.0.0.1:9306")
c = Oedipus.connect(host: "127.0.0.1", port: 9306)
c = Oedipus.connect("127.0.0.1:9306", :dist_host)

Parameters:

  • server (String|Hash)

    a ‘hostname:port’ string, or a Hash with :host and :port keys

  • key (Object) (defaults to: :default)

    an optional name for the connection

Returns:



31
32
33
# File 'lib/oedipus/connection/registry.rb', line 31

def connect(options, key = :default)
  connections[key] = Connection.new(options)
end

#connection(key = :default) ⇒ Connection

Lookup an already connected connection.

Examples:

c = Oedipus.connection
c = Oedipus.connection(:dist_host)

Parameters:

  • key (Object) (defaults to: :default)

    an optional name for the connection

Returns:

Raises:

  • (ArgumentError)


46
47
48
49
# File 'lib/oedipus/connection/registry.rb', line 46

def connection(key = :default)
  raise ArgumentError, "Connection #{key} is not defined" unless connections.key?(key)
  connections[key]
end

#connectionsObject



51
52
53
# File 'lib/oedipus/connection/registry.rb', line 51

def connections
  @connections ||= {}
end