Class: CassandraModel::TableRedux

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/cassandra_model/table_redux.rb

Direct Known Subclasses

MetaTable

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection_name = nil, table_name) ⇒ TableRedux

Returns a new instance of TableRedux.



7
8
9
10
# File 'lib/cassandra_model/table_redux.rb', line 7

def initialize(connection_name = nil, table_name)
  @name = table_name.to_s
  @connection_name = connection_name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/cassandra_model/table_redux.rb', line 5

def name
  @name
end

Instance Method Details

#allow_truncation!Object



21
22
23
# File 'lib/cassandra_model/table_redux.rb', line 21

def allow_truncation!
  @allow_truncation = true
end

#clustering_columnsObject



40
41
42
# File 'lib/cassandra_model/table_redux.rb', line 40

def clustering_columns
  @clustering_columns ||= table.send(:clustering_columns).map { |column| column.name.to_sym }
end

#columnsObject



48
49
50
# File 'lib/cassandra_model/table_redux.rb', line 48

def columns
  @columns ||= table.columns.map { |column| column.name.to_sym }
end

#connectionObject



17
18
19
# File 'lib/cassandra_model/table_redux.rb', line 17

def connection
  ConnectionCache[@connection_name]
end

#in_context(time) {|_self| ... } ⇒ Object

noinspection RubyUnusedLocalVariable

Yields:

  • (_self)

Yield Parameters:



13
14
15
# File 'lib/cassandra_model/table_redux.rb', line 13

def in_context(time)
  yield self
end

#partition_keyObject



36
37
38
# File 'lib/cassandra_model/table_redux.rb', line 36

def partition_key
  @partition_key ||= table.send(:partition_key).map { |column| column.name.to_sym }
end

#primary_keyObject



44
45
46
# File 'lib/cassandra_model/table_redux.rb', line 44

def primary_key
  partition_key + clustering_columns
end

#reset_local_schema!Object



30
31
32
33
34
# File 'lib/cassandra_model/table_redux.rb', line 30

def reset_local_schema!
  @partition_key = nil
  @clustering_columns = nil
  @columns = nil
end

#truncate!Object



25
26
27
28
# File 'lib/cassandra_model/table_redux.rb', line 25

def truncate!
  raise "Truncation not enabled for table '#{name}'" unless @allow_truncation
  connection.session.execute("TRUNCATE #{name}")
end