Module: CassandraModel::CompositeRecordStatic
- Extended by:
- Forwardable
- Defined in:
- lib/cassandra_model/composite_record_static.rb
Overview
noinspection ALL
Class Method Summary collapse
Instance Method Summary collapse
- #clustering_columns ⇒ Object
- #columns ⇒ Object (also: #ensure_attributes_accessible!)
- #composite_ck_map ⇒ Object
- #composite_defaults ⇒ Object
- #composite_pk_map ⇒ Object
- #denormalized_column_map(input_columns) ⇒ Object
- #generate_composite_defaults(column_defaults, truth_table) ⇒ Object
- #generate_composite_defaults_from_inquirer(inquirer) ⇒ Object
- #normalized_attributes(attributes) ⇒ Object
- #normalized_column(column) ⇒ Object
- #partition_key ⇒ Object
- #primary_key ⇒ Object
- #restriction_attributes(restriction) ⇒ Object
- #select_column(column) ⇒ Object
- #select_columns(columns) ⇒ Object
- #shard_key ⇒ Object
Class Method Details
.extended(base) ⇒ Object
8 9 10 |
# File 'lib/cassandra_model/composite_record_static.rb', line 8 def self.extended(base) base.instance_variable_set(:@mutex, Mutex.new) end |
Instance Method Details
#clustering_columns ⇒ Object
16 17 18 |
# File 'lib/cassandra_model/composite_record_static.rb', line 16 def clustering_columns table_data.composite_clustering_columns ||= internal_clustering_columns.map { |column| trim_column!(column, /^ck_/, composite_ck_map) || column } end |
#columns ⇒ Object Also known as: ensure_attributes_accessible!
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/cassandra_model/composite_record_static.rb', line 28 def columns unless table_data.composite_columns @mutex.synchronize do return table_data.composite_columns if table_data.composite_columns table_data.composite_pk_map = {} table_data.composite_ck_map = {} table_data.composite_columns = composite_columns.each { |column| define_attribute(column) } end end table_data.composite_columns end |
#composite_ck_map ⇒ Object
62 63 64 65 |
# File 'lib/cassandra_model/composite_record_static.rb', line 62 def composite_ck_map ensure_attributes_accessible! unless table_data.composite_columns table_data.composite_ck_map end |
#composite_defaults ⇒ Object
67 68 69 |
# File 'lib/cassandra_model/composite_record_static.rb', line 67 def composite_defaults table_data.internal_defaults ||= build_composite_map end |
#composite_pk_map ⇒ Object
57 58 59 60 |
# File 'lib/cassandra_model/composite_record_static.rb', line 57 def composite_pk_map ensure_attributes_accessible! unless table_data.composite_columns table_data.composite_pk_map end |
#denormalized_column_map(input_columns) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/cassandra_model/composite_record_static.rb', line 43 def denormalized_column_map(input_columns) internal_columns.inject({}) do |memo, column| result_column = input_columns.find { |input_column| input_column == column } unless result_column trimmed_column = trimmed_column(column, /^rk_/) || trimmed_column(column, /^ck_/) || column result_column = input_columns.find { |input_column| input_column == trimmed_column } end memo[column] = result_column if result_column memo end end |
#generate_composite_defaults(column_defaults, truth_table) ⇒ Object
71 72 73 |
# File 'lib/cassandra_model/composite_record_static.rb', line 71 def generate_composite_defaults(column_defaults, truth_table) table_config.composite_defaults = truth_table.map { |row| column_defaults.except(*row) } end |
#generate_composite_defaults_from_inquirer(inquirer) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/cassandra_model/composite_record_static.rb', line 75 def generate_composite_defaults_from_inquirer(inquirer) table_config.composite_defaults = inquirer.composite_rows.map do |row| row.inject({}) do |memo, column| memo.merge!(column => inquirer.column_defaults[column]) end end end |
#normalized_attributes(attributes) ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/cassandra_model/composite_record_static.rb', line 112 def normalized_attributes(attributes) attributes = super(attributes) attributes.inject({}) do |memo, (column, value)| memo.merge!(normalized_column(column) => value) end end |
#normalized_column(column) ⇒ Object
102 103 104 105 106 107 108 109 110 |
# File 'lib/cassandra_model/composite_record_static.rb', line 102 def normalized_column(column) column = super(column) if column =~ /^rk_/ || column =~ /^ck_/ mapped_column(column) else column end end |
#partition_key ⇒ Object
12 13 14 |
# File 'lib/cassandra_model/composite_record_static.rb', line 12 def partition_key table_data.composite_partition_key ||= internal_partition_key.map { |column| trim_column!(column, /^rk_/, composite_pk_map) || column } end |
#primary_key ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/cassandra_model/composite_record_static.rb', line 20 def primary_key table_data.composite_primary_key ||= (internal_partition_key + internal_clustering_columns).map do |column| trim_column!(column, /^rk_/, composite_pk_map) || trim_column!(column, /^ck_/, composite_ck_map) || column end.uniq end |
#restriction_attributes(restriction) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/cassandra_model/composite_record_static.rb', line 90 def restriction_attributes(restriction) updated_restriction = restriction.inject({}) do |memo, (key, value)| updated_key = key_for_where_params(key) memo.merge!(updated_key => value) end missing_keys = Set.new(internal_partition_key - updated_restriction.keys) default_clause = composite_defaults.find { |row| (missing_keys ^ row.keys).empty? } updated_restriction.merge!(default_clause) if default_clause updated_restriction end |
#select_column(column) ⇒ Object
124 125 126 |
# File 'lib/cassandra_model/composite_record_static.rb', line 124 def select_column(column) has_field?(column) ? column : mapped_column(column) end |
#select_columns(columns) ⇒ Object
120 121 122 |
# File 'lib/cassandra_model/composite_record_static.rb', line 120 def select_columns(columns) columns.map { |column| select_column(column) } end |
#shard_key ⇒ Object
83 84 85 86 87 88 |
# File 'lib/cassandra_model/composite_record_static.rb', line 83 def shard_key table_data.composite_shard_key ||= begin column = super column =~ /^rk_/ ? composite_pk_map[column] : column end end |