Class: CassandraObject::Adapters::CassandraDriver
- Inherits:
-
Object
- Object
- CassandraObject::Adapters::CassandraDriver
- Defined in:
- lib/cassandra_object/adapters/cassandra_driver.rb
Defined Under Namespace
Classes: Client
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #client ⇒ Object
- #close ⇒ Object
- #cluster ⇒ Object
- #cluster_config ⇒ Object
-
#initialize(config) ⇒ CassandraDriver
constructor
A new instance of CassandraDriver.
- #new_client ⇒ Object
Constructor Details
#initialize(config) ⇒ CassandraDriver
Returns a new instance of CassandraDriver.
6 7 8 |
# File 'lib/cassandra_object/adapters/cassandra_driver.rb', line 6 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
4 5 6 |
# File 'lib/cassandra_object/adapters/cassandra_driver.rb', line 4 def config @config end |
Instance Method Details
#client ⇒ Object
14 15 16 |
# File 'lib/cassandra_object/adapters/cassandra_driver.rb', line 14 def client @client ||= self.new_client end |
#close ⇒ Object
22 23 24 25 |
# File 'lib/cassandra_object/adapters/cassandra_driver.rb', line 22 def close @client.try(:close) @client = nil end |
#cluster ⇒ Object
10 11 12 |
# File 'lib/cassandra_object/adapters/cassandra_driver.rb', line 10 def cluster @cluster ||= Cassandra.cluster cluster_config end |
#cluster_config ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/cassandra_object/adapters/cassandra_driver.rb', line 27 def cluster_config { :hosts => config[:servers].map { |server| server.sub /:\d+/, '' }, :port => config[:port] || 9042, :connect_timeout => config[:thrift][:connect_timeout] || 10, :timeout => config[:thrift][:timeout] || 10, :logger => config[:logger] || (defined?(Rails) && Rails.logger) || Logger.new(STDOUT), :consistency => (config[:consistency] || {})[:write_default].try(:to_sym) || :one, } end |