Class: CassandraModel::DataInquirer
- Inherits:
-
Object
- Object
- CassandraModel::DataInquirer
- Includes:
- TypeGuessing
- Defined in:
- lib/cassandra_model/data_inquirer.rb
Defined Under Namespace
Classes: ColumnDefault, ColumnType
Instance Attribute Summary collapse
-
#column_defaults ⇒ Object
readonly
Returns the value of attribute column_defaults.
-
#partition_key ⇒ Object
readonly
Returns the value of attribute partition_key.
-
#shard_column ⇒ Object
readonly
Returns the value of attribute shard_column.
Instance Method Summary collapse
- #change_type_of(column) ⇒ Object
- #composite_rows ⇒ Object
- #defaults(column) ⇒ Object
-
#initialize ⇒ DataInquirer
constructor
A new instance of DataInquirer.
- #knows_about(*columns) ⇒ Object
- #shards_queries(column = :shard) ⇒ Object
Methods included from TypeGuessing
Constructor Details
#initialize ⇒ DataInquirer
Returns a new instance of DataInquirer.
7 8 9 10 11 |
# File 'lib/cassandra_model/data_inquirer.rb', line 7 def initialize @partition_key = Hash.new { |hash, key| hash[key] = :text } @column_defaults = Hash.new { |hash, key| hash[key] = '' } @known_keys = [] end |
Instance Attribute Details
#column_defaults ⇒ Object (readonly)
Returns the value of attribute column_defaults.
5 6 7 |
# File 'lib/cassandra_model/data_inquirer.rb', line 5 def column_defaults @column_defaults end |
#partition_key ⇒ Object (readonly)
Returns the value of attribute partition_key.
5 6 7 |
# File 'lib/cassandra_model/data_inquirer.rb', line 5 def partition_key @partition_key end |
#shard_column ⇒ Object (readonly)
Returns the value of attribute shard_column.
5 6 7 |
# File 'lib/cassandra_model/data_inquirer.rb', line 5 def shard_column @shard_column end |
Instance Method Details
#change_type_of(column) ⇒ Object
38 39 40 41 |
# File 'lib/cassandra_model/data_inquirer.rb', line 38 def change_type_of(column) raise "Cannot retype unknown column #{column}" unless partition_key.include?(column) ColumnType.new(column, self) end |
#composite_rows ⇒ Object
27 28 29 30 31 |
# File 'lib/cassandra_model/data_inquirer.rb', line 27 def composite_rows @known_keys.map do |row| partition_key.keys - row end.reject(&:empty?) end |
#defaults(column) ⇒ Object
33 34 35 36 |
# File 'lib/cassandra_model/data_inquirer.rb', line 33 def defaults(column) raise "Cannot default unknown column #{column}" unless partition_key.include?(column) ColumnDefault.new(column, self) end |
#knows_about(*columns) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/cassandra_model/data_inquirer.rb', line 13 def knows_about(*columns) columns.each do |column| partition_key[column] guess_data_type(column) if @guess_data_types column_defaults[column] end @known_keys << columns self end |
#shards_queries(column = :shard) ⇒ Object
23 24 25 |
# File 'lib/cassandra_model/data_inquirer.rb', line 23 def shards_queries(column = :shard) @shard_column = column end |