Class: Cassie::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/cassie/config.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Returns a new instance of Config.



23
24
25
26
27
28
29
30
# File 'lib/cassie/config.rb', line 23

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

Instance Attribute Details

#clusterObject (readonly)

Returns the value of attribute cluster.



20
21
22
# File 'lib/cassie/config.rb', line 20

def cluster
  @cluster
end

#default_keyspaceObject

Returns the value of attribute default_keyspace.



21
22
23
# File 'lib/cassie/config.rb', line 21

def default_keyspace
  @default_keyspace
end

#max_prepared_statementsObject

Returns the value of attribute max_prepared_statements.



21
22
23
# File 'lib/cassie/config.rb', line 21

def max_prepared_statements
  @max_prepared_statements
end

#schema_directoryObject

Returns the value of attribute schema_directory.



21
22
23
# File 'lib/cassie/config.rb', line 21

def schema_directory
  @schema_directory
end

Instance Method Details

#add_keyspace(name, value) ⇒ Object

Add a mapping of a name to a keyspace.



48
49
50
# File 'lib/cassie/config.rb', line 48

def add_keyspace(name, value)
  @keyspaces[name.to_s] = value
end

#keyspace(name) ⇒ Object

Get the actual keyspace mapped to the abstract name.



33
34
35
# File 'lib/cassie/config.rb', line 33

def keyspace(name)
  @keyspaces[name.to_s] || name.to_s
end

#keyspace_namesObject

Get the list of abstract keyspace names.



43
44
45
# File 'lib/cassie/config.rb', line 43

def keyspace_names
  @keyspaces.keys
end

#keyspacesObject

Get the list of keyspaces defined for the cluster.



38
39
40
# File 'lib/cassie/config.rb', line 38

def keyspaces
  @keyspaces.values
end

#sanitized_clusterObject

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



53
54
55
56
57
58
59
60
61
# File 'lib/cassie/config.rb', line 53

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