Class: CassSchema::DataStore
- Inherits:
-
Struct
- Object
- Struct
- CassSchema::DataStore
- Defined in:
- lib/cass_schema/datastore.rb
Overview
A struct representing a datastore, composed of the following fields: “{ ‘class’ : ‘SimpleStrategy’, ‘replication_factor’ : 3 }” statements are separated by two new lines, and a statement cannot have two newlines inside of it comments start with ‘#’
Instance Attribute Summary collapse
-
#cluster ⇒ Object
Returns the value of attribute cluster.
-
#keyspace ⇒ Object
Returns the value of attribute keyspace.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#name ⇒ Object
Returns the value of attribute name.
-
#replication ⇒ Object
Returns the value of attribute replication.
-
#schema ⇒ Object
Returns the value of attribute schema.
-
#schema_base_path ⇒ Object
Returns the value of attribute schema_base_path.
Class Method Summary collapse
-
.build(name, hash) ⇒ Object
Creates a datastore object from a hash containing the required keys.
Instance Method Summary collapse
-
#_setup(options = {}) ⇒ Object
Internal method used by Runner to pass state into the datastore.
-
#client ⇒ Cassandra::Session
A Cassava client connected to the cluster and keyspace with which this datastore is associated.
-
#create ⇒ Object
Creates the datastore.
-
#drop ⇒ Object
Drops the datastore.
-
#general_client ⇒ Cassandra::Session
A Cassava client connected to the cluster with which this datastore is associated.
-
#migrate(migration_name) ⇒ Object
Runs a given migration for this datastore.
- #schema_path ⇒ Object
Instance Attribute Details
#cluster ⇒ Object
Returns the value of attribute cluster
18 19 20 |
# File 'lib/cass_schema/datastore.rb', line 18 def cluster @cluster end |
#keyspace ⇒ Object
Returns the value of attribute keyspace
18 19 20 |
# File 'lib/cass_schema/datastore.rb', line 18 def keyspace @keyspace end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
20 21 22 |
# File 'lib/cass_schema/datastore.rb', line 20 def logger @logger end |
#name ⇒ Object
Returns the value of attribute name
18 19 20 |
# File 'lib/cass_schema/datastore.rb', line 18 def name @name end |
#replication ⇒ Object
Returns the value of attribute replication
18 19 20 |
# File 'lib/cass_schema/datastore.rb', line 18 def replication @replication end |
#schema ⇒ Object
Returns the value of attribute schema
18 19 20 |
# File 'lib/cass_schema/datastore.rb', line 18 def schema @schema end |
#schema_base_path ⇒ Object
Returns the value of attribute schema_base_path
18 19 20 |
# File 'lib/cass_schema/datastore.rb', line 18 def schema_base_path @schema_base_path end |
Class Method Details
.build(name, hash) ⇒ Object
Creates a datastore object from a hash containing the required keys
28 29 30 31 32 |
# File 'lib/cass_schema/datastore.rb', line 28 def self.build(name, hash) l = hash.with_indifferent_access schema = l[:schema] || name new(name, l[:cluster], l[:keyspace], l[:replication], schema, l[:schema_base_path]) end |
Instance Method Details
#_setup(options = {}) ⇒ Object
Internal method used by Runner to pass state into the datastore
64 65 66 67 |
# File 'lib/cass_schema/datastore.rb', line 64 def _setup( = {}) self.schema_base_path ||= [:schema_base_path] @logger = [:logger] end |
#client ⇒ Cassandra::Session
A Cassava client connected to the cluster and keyspace with which this datastore is associated
53 54 55 |
# File 'lib/cass_schema/datastore.rb', line 53 def client @client ||= cluster.connection.connect(keyspace) end |
#create ⇒ Object
Creates the datastore
35 36 37 38 |
# File 'lib/cass_schema/datastore.rb', line 35 def create run_statement(create_keyspace, general_client) create_statements.each { |statement| run_statement(statement, client) } end |
#drop ⇒ Object
Drops the datastore
41 42 43 |
# File 'lib/cass_schema/datastore.rb', line 41 def drop run_statement(drop_keyspace, general_client) end |
#general_client ⇒ Cassandra::Session
A Cassava client connected to the cluster with which this datastore is associated
59 60 61 |
# File 'lib/cass_schema/datastore.rb', line 59 def general_client @general_client ||= cluster.connection.connect end |
#migrate(migration_name) ⇒ Object
Runs a given migration for this datastore
47 48 49 |
# File 'lib/cass_schema/datastore.rb', line 47 def migrate(migration_name) migration_statements(migration_name).each { |statement| run_statement(statement, client) } end |
#schema_path ⇒ Object
69 70 71 |
# File 'lib/cass_schema/datastore.rb', line 69 def schema_path File.join(schema_base_path, schema, 'schema.cql') end |