Module: CassandraObject::Connection::ClassMethods

Defined in:
lib/cassandra_object/connection.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  servers: "127.0.0.1:9160",
}
DEFAULT_THRIFT_OPTIONS =
{
  exception_class_overrides: [],
}
@@connection =
nil

Instance Method Summary collapse

Instance Method Details

#connectionObject



46
47
48
# File 'lib/cassandra_object/connection.rb', line 46

def connection
  @@connection ||= CassandraObject::Adapters::CassandraDriver.new(self.connection_spec).client
end

#connection?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/cassandra_object/connection.rb', line 50

def connection?
  !! @@connection
end

#disconnect!Object



54
55
56
57
# File 'lib/cassandra_object/connection.rb', line 54

def disconnect!
  @@connection.try(:close)
  @@connection = nil
end

#establish_connection(config) ⇒ Object

This doesn’t open a connection. It merely conifgures the connection object.



36
37
38
39
40
41
42
43
# File 'lib/cassandra_object/connection.rb', line 36

def establish_connection(config)
  spec = config.reverse_merge(DEFAULT_OPTIONS)

  spec[:thrift] = (spec[:thrift] || {}).reverse_merge(DEFAULT_THRIFT_OPTIONS)
  spec[:thrift][:exception_class_overrides] = spec[:thrift][:exception_class_overrides].map(&:constantize)

  self.connection_spec = spec
end

#with_connection(*args) ⇒ Object



59
60
61
# File 'lib/cassandra_object/connection.rb', line 59

def with_connection(*args)
  yield
end