class Cassandra::ColumnContainer
This class contains all the logic needed for manipulating columns of an object.
Attributes
@return [Array<Cassandra::Column>] ordered list of column-names that make up the clustering-columns.
@return [Cassandra::Uuid] the id of this object in Cassandra
.
@return [Cassandra::Keyspace] the keyspace that this column-container belongs to.
@return [String] name of this column-container
@return [ColumnContainer::Options] collection of configuration options of this column-container.
@return [Array<Cassandra::Column>] ordered list of column-names that make up the partition-key.
@return [Array<Cassandra::Column>] primary key of this column-container. It's the combination of
`partition_key` and `clustering_columns`.
@note This composition produces a flat list, so it will not be possible for the caller to distinguish
partition-key columns from clustering-columns.
Public Class Methods
@private
# File lib/cassandra/column_container.rb 238 def initialize(keyspace, 239 name, 240 partition_key, 241 clustering_columns, 242 other_columns, 243 options, 244 id) 245 @keyspace = keyspace 246 @name = name.freeze 247 @partition_key = partition_key.freeze 248 @clustering_columns = clustering_columns.freeze 249 @options = options 250 @id = id 251 252 # Make one array of all the columns, ordered with partition key, clustering 253 # columns, then other columns. Make a hash as well, to support random access 254 # to column metadata for a given column name. Save off the primary key (which 255 # is partition-key + clustering-columns) while we're at it. 256 257 @primary_key = @partition_key.dup.concat(@clustering_columns).freeze 258 @columns = @primary_key.dup.concat(other_columns).freeze 259 @columns_hash = @columns.each_with_object({}) do |col, h| 260 h[col.name] = col 261 end 262 end
Public Instance Methods
@param name [String] column name @return [Cassandra::Column, nil] a column or nil
# File lib/cassandra/column_container.rb 272 def column(name) 273 @columns_hash[name] 274 end
Yield or enumerate each column defined in this column-container @overload each_column
@yieldparam column [Cassandra::Column] current column @return [Cassandra::ColumnContainer] self
@overload each_column
@return [Array<Cassandra::Column>] a list of columns
# File lib/cassandra/column_container.rb 282 def each_column(&block) 283 if block_given? 284 @columns.each(&block) 285 self 286 else 287 @columns 288 end 289 end
@private
# File lib/cassandra/column_container.rb 309 def eql?(other) 310 other.is_a?(ColumnContainer) && 311 @keyspace == other.keyspace && 312 @name == other.name && 313 @partition_key == other.partition_key && 314 @clustering_columns == other.clustering_columns && 315 @columns == other.raw_columns && 316 @options == other.options 317 end
@param name [String] column name @return [Boolean] whether this column-container has a given column
# File lib/cassandra/column_container.rb 266 def has_column?(name) 267 @columns_hash.key?(name) 268 end
@private
# File lib/cassandra/column_container.rb 303 def inspect 304 "#<#{self.class.name}:0x#{object_id.to_s(16)} " \ 305 "@keyspace=#{@keyspace.name} @name=#{@name}>" 306 end
@private keyspace attribute may be nil because when this object was constructed, we didn't have its keyspace constructed yet. So allow updating @keyspace, thus allowing fetchers to create keyspace, table/view, and hook them together without worrying about chickens and eggs. rubocop:disable Naming/AccessorMethodName
# File lib/cassandra/column_container.rb 298 def set_keyspace(keyspace) 299 @keyspace = keyspace 300 end
Protected Instance Methods
@private
# File lib/cassandra/column_container.rb 321 def raw_columns 322 @columns 323 end