Class: Cassandra::Mocks::Keyspace
- Inherits:
-
Keyspace
- Object
- Keyspace
- Cassandra::Mocks::Keyspace
- Defined in:
- lib/cassandra_mocks/keyspace.rb
Instance Method Summary collapse
- #add_table(table_name, primary_key, columns) ⇒ Object
- #drop_table(table_name) ⇒ Object
-
#initialize(name) ⇒ Keyspace
constructor
A new instance of Keyspace.
Constructor Details
#initialize(name) ⇒ Keyspace
Returns a new instance of Keyspace.
5 6 7 8 |
# File 'lib/cassandra_mocks/keyspace.rb', line 5 def initialize(name) replication = Replication.new('mock', {}) super(name, false, replication, {}) end |
Instance Method Details
#add_table(table_name, primary_key, columns) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/cassandra_mocks/keyspace.rb', line 10 def add_table(table_name, primary_key, columns) raise Errors::InvalidError.new("Table name '#{table_name}' cannot be greater than 48 characters", 'MockStatement') if table_name.length > 48 raise Errors::AlreadyExistsError.new('Cannot create already existing table', 'MockStatement', nil, table_name) if @tables[table_name] partition_key = primary_key.shift partition_key_columns = partition_key_part(columns, partition_key) clustering_columns = partition_key_part(columns, primary_key) fields = fields(columns, partition_key, primary_key) @tables[table_name] = Table.new(name, table_name, partition_key_columns, clustering_columns, fields) end |
#drop_table(table_name) ⇒ Object
21 22 23 |
# File 'lib/cassandra_mocks/keyspace.rb', line 21 def drop_table(table_name) @tables.delete(table_name) end |