Class: CassandraModel::TableRedux

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

Direct Known Subclasses

MetaTable

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TableDebug

#debug

Constructor Details

#initialize(connection_name = nil, table_name) ⇒ TableRedux

Returns a new instance of TableRedux.



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

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.



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

def name
  @name
end

Instance Method Details

#allow_truncation!Object



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

def allow_truncation!
  @allow_truncation = true
end

#clustering_columnsObject



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

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

#columnsObject



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

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

#connectionObject



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

def connection
  ConnectionCache[@connection_name]
end

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

noinspection RubyUnusedLocalVariable

Yields:

  • (_self)

Yield Parameters:



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

def in_context(time)
  yield self
end

#partition_keyObject



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

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

#primary_keyObject



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

def primary_key
  partition_key + clustering_columns
end

#reset_local_schema!Object



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

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

#truncate!Object



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

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