Module: Cassie::ConnectionHandler::Cluster

Extended by:
ActiveSupport::Concern
Included in:
Cassie::ConnectionHandler
Defined in:
lib/cassie/connection_handler/cluster.rb,
lib/cassie/connection_handler/cluster/instrumentation.rb

Overview

## Cassie::ConnectionHandler::Cluster

Adds cluster instance configuration and memoization.

Include in any class or module that responds to ‘configuration` with a cassandra cluster options hash.

Defined Under Namespace

Modules: Instrumentation

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clusterCassandra::Cluster (readonly)

The cluster connection and metadata. This cluster connection is lazy-loaded, not calling out to Cassandra until it is first accessed. The single cluster object is cached for the entire process.



21
22
23
24
25
26
# File 'lib/cassie/connection_handler/cluster.rb', line 21

def cluster
  # Cassandra::cluster parses suppored
  # options from the passed hash, no need
  # to validate/transform ourselves yet
  @cluster ||= initialize_cluster
end

Instance Method Details

#keyspace_exists?(name) ⇒ Boolean



30
31
32
# File 'lib/cassie/connection_handler/cluster.rb', line 30

def keyspace_exists?(name)
  cluster.keyspaces.map(&:name).any?{|k| k.to_s == name.to_s}
end

#table_exists?(name) ⇒ Boolean



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cassie/connection_handler/cluster.rb', line 38

def table_exists?(name)
  keyspaces = {}
  name = "#{keyspace}.#{name}" unless name.to_s.include? "."
  matches = name.match(/(.*)\.(.*)/)
  space = matches[1]
  table = matches[2]
  cluster.keyspaces.each {|k| keyspaces[k.name.to_s] = k }

  return false unless keyspaces.has_key?(space)
  keyspaces[space].tables.map(&:name).any?{|t| t.to_s == table}
end