class Rethinker::Connection

Attributes

database_name[RW]

A connection is bound to a specific database.

host[RW]

A connection is bound to a specific database.

port[RW]

A connection is bound to a specific database.

uri[RW]

A connection is bound to a specific database.

Public Class Methods

new(uri) click to toggle source
# File lib/rethinker/connection.rb, line 6
def initialize(uri)
  self.uri = uri
  parse_uri
end

Public Instance Methods

connect()
Alias for: raw
database() click to toggle source
# File lib/rethinker/connection.rb, line 26
def database
  @database ||= Rethinker::Database.new(self)
end
raw() click to toggle source
# File lib/rethinker/connection.rb, line 11
def raw
  @raw ||= RethinkDB::Connection.new(:host => host, :port => port, :db => database_name)
end
Also aliased as: connect

Private Instance Methods

apply_connection_settings!(uri) click to toggle source
# File lib/rethinker/connection.rb, line 44
def apply_connection_settings!(uri)
  self.host = uri.host
  self.port = uri.port || 28015
  self.database_name = uri.path.gsub(/^\//, '')
end
parse_uri() click to toggle source
# File lib/rethinker/connection.rb, line 32
def parse_uri
  require 'uri'
  parsed_uri = URI.parse(uri)

  if parsed_uri.scheme != 'rethinkdb'
    raise Rethinker::Error::Connection,
      "Invalid URI. Expecting something like rethinkdb://host:port/database. Got #{uri}"
  end

  apply_connection_settings!(parsed_uri)
end