Class: CassSchema::DataStore

Inherits:
Struct
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clusterObject

Returns the value of attribute cluster

Returns:

  • (Object)

    the current value of cluster



18
19
20
# File 'lib/cass_schema/datastore.rb', line 18

def cluster
  @cluster
end

#keyspaceObject

Returns the value of attribute keyspace

Returns:

  • (Object)

    the current value of keyspace



18
19
20
# File 'lib/cass_schema/datastore.rb', line 18

def keyspace
  @keyspace
end

#loggerObject (readonly)

Returns the value of attribute logger.



20
21
22
# File 'lib/cass_schema/datastore.rb', line 20

def logger
  @logger
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



18
19
20
# File 'lib/cass_schema/datastore.rb', line 18

def name
  @name
end

#replicationObject

Returns the value of attribute replication

Returns:

  • (Object)

    the current value of replication



18
19
20
# File 'lib/cass_schema/datastore.rb', line 18

def replication
  @replication
end

#schemaObject

Returns the value of attribute schema

Returns:

  • (Object)

    the current value of schema



18
19
20
# File 'lib/cass_schema/datastore.rb', line 18

def schema
  @schema
end

#schema_base_pathObject

Returns the value of attribute schema_base_path

Returns:

  • (Object)

    the current value of 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

Parameters:

  • name (String)

    of the data store

  • [CassSchema::Cluster] (Hash)

    a customizable set of options

  • [String] (Hash)

    a customizable set of options



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(options = {})
  self.schema_base_path ||= options[:schema_base_path]
  @logger = options[:logger]
end

#clientCassandra::Session

A Cassava client connected to the cluster and keyspace with which this datastore is associated

Returns:

  • (Cassandra::Session)


53
54
55
# File 'lib/cass_schema/datastore.rb', line 53

def client
  @client ||= cluster.connection.connect(keyspace)
end

#createObject

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

#dropObject

Drops the datastore



41
42
43
# File 'lib/cass_schema/datastore.rb', line 41

def drop
  run_statement(drop_keyspace, general_client)
end

#general_clientCassandra::Session

A Cassava client connected to the cluster with which this datastore is associated

Returns:

  • (Cassandra::Session)


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

Parameters:

  • migration_name (String)

    the name of the migration



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_pathObject



69
70
71
# File 'lib/cass_schema/datastore.rb', line 69

def schema_path
  File.join(schema_base_path, schema, 'schema.cql')
end