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: [], }
Instance Method Summary collapse
- #connection ⇒ Object
- #connection? ⇒ Boolean
- #disconnect! ⇒ Object
-
#establish_connection(config) ⇒ Object
This doesn’t open a connection.
- #with_connection(*args) ⇒ Object
Instance Method Details
#connection ⇒ Object
45 46 47 |
# File 'lib/cassandra_object/connection.rb', line 45 def connection @connection ||= CassandraObject::Adapters::CassandraDriver.new(self.connection_spec).client end |
#connection? ⇒ Boolean
49 50 51 |
# File 'lib/cassandra_object/connection.rb', line 49 def connection? !! @connection end |
#disconnect! ⇒ Object
53 54 55 56 |
# File 'lib/cassandra_object/connection.rb', line 53 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
58 59 60 |
# File 'lib/cassandra_object/connection.rb', line 58 def with_connection(*args) yield end |