class Cassie::Config

Simple configuration for connecting to Cassandra.

:cluster should be a Hash of the options to initialize the Cassandra cluster. See datastax.github.io/ruby-driver/api/#cluster-class_method for details.

:keyspaces are a map of abstract keyspace names to actual names. These can be used in lieu of hard coding keyspace names and can be especially useful if keyspaces differ between environments. The abstract names can then be used when defining the keyspace for a model.

:default_keyspace is an optional keyspace name to use as the default. It can be either the actual name or an abstract name mapped to an actual name in the keyspaces map.

:max_prepared_statements is the maximum number of prepared statements that will be kept cached on the client (default 1000).

:schema_directory is an optional path to the location where you schema files are stored. This should only be set in development and test environments since schema statements can be destructive in production.

Attributes

cluster[R]
default_keyspace[RW]
max_prepared_statements[RW]
schema_directory[RW]

Public Class Methods

new(options = {}) click to toggle source
# File lib/cassie/config.rb, line 25
def initialize(options = {})
  options = options.symbolize_keys
  @cluster = (options[:cluster] || {}).symbolize_keys
  @keyspaces = (options[:keyspaces] || {}).stringify_keys
  @max_prepared_statements = (options[:max_prepared_statements] || 1000)
  @schema_directory = options[:schema_directory]
  @default_keyspace = options[:default_keyspace]
end

Public Instance Methods

add_keyspace(name, value) click to toggle source

Add a mapping of a name to a keyspace.

# File lib/cassie/config.rb, line 50
def add_keyspace(name, value)
  @keyspaces[name.to_s] = value
end
keyspace(name) click to toggle source

Get the actual keyspace mapped to the abstract name.

# File lib/cassie/config.rb, line 35
def keyspace(name)
  @keyspaces[name.to_s] || name.to_s
end
keyspace_names() click to toggle source

Get the list of abstract keyspace names.

# File lib/cassie/config.rb, line 45
def keyspace_names
  @keyspaces.keys
end
keyspaces() click to toggle source

Get the list of keyspaces defined for the cluster.

# File lib/cassie/config.rb, line 40
def keyspaces
  @keyspaces.values
end
sanitized_cluster() click to toggle source

Return the cluster options without passwords or tokens. Used for logging.

# File lib/cassie/config.rb, line 55
def sanitized_cluster
  options = cluster.dup
  options[:password] = "SUPPRESSED" if options.include?(:password)
  options[:passphrase] = "SUPPRESSED" if options.include?(:passphrase)
  options[:credentials] = "SUPPRESSED" if options.include?(:credentials)
  options[:auth_provider] = "SUPPRESSED" if options.include?(:auth_provider)
  options[:logger] = options[:logger].class.name if options.include?(:logger)
  options
end