Class: Cassie::Config
- Inherits:
-
Object
- Object
- Cassie::Config
- 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
-
#cluster ⇒ Object
readonly
Returns the value of attribute cluster.
-
#default_keyspace ⇒ Object
Returns the value of attribute default_keyspace.
-
#max_prepared_statements ⇒ Object
Returns the value of attribute max_prepared_statements.
-
#schema_directory ⇒ Object
Returns the value of attribute schema_directory.
Instance Method Summary collapse
-
#add_keyspace(name, value) ⇒ Object
Add a mapping of a name to a keyspace.
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
-
#keyspace(name) ⇒ Object
Get the actual keyspace mapped to the abstract name.
-
#keyspace_names ⇒ Object
Get the list of abstract keyspace names.
-
#keyspaces ⇒ Object
Get the list of keyspaces defined for the cluster.
-
#sanitized_cluster ⇒ Object
Return the cluster options without passwords or tokens.
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( = {}) = .symbolize_keys @cluster = ([:cluster] || {}).symbolize_keys @keyspaces = ([:keyspaces] || {}).stringify_keys @max_prepared_statements = ([:max_prepared_statements] || 1000) @schema_directory = [:schema_directory] @default_keyspace = [:default_keyspace] end |
Instance Attribute Details
#cluster ⇒ Object (readonly)
Returns the value of attribute cluster.
20 21 22 |
# File 'lib/cassie/config.rb', line 20 def cluster @cluster end |
#default_keyspace ⇒ Object
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_statements ⇒ Object
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_directory ⇒ Object
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_names ⇒ Object
Get the list of abstract keyspace names.
43 44 45 |
# File 'lib/cassie/config.rb', line 43 def keyspace_names @keyspaces.keys end |
#keyspaces ⇒ Object
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_cluster ⇒ Object
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 = cluster.dup [:password] = "SUPPRESSED" if .include?(:password) [:passphrase] = "SUPPRESSED" if .include?(:passphrase) [:credentials] = "SUPPRESSED" if .include?(:credentials) [:auth_provider] = "SUPPRESSED" if .include?(:auth_provider) [:logger] = [:logger].class.name if .include?(:logger) end |