Module: Cequel::Record::Properties
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/cequel/record/properties.rb
Overview
Properties on a Cequel record acts as attributes on record instances, and are persisted as column values to Cassandra. Properties are declared explicitly on a record instance in the body.
Properties can be **key columns**, **data columns**, or **collection columns**. Key columns combine to form the primary key for the record; they cannot be changed once a record has been saved. Data columns contain scalar data values like strings, integers, and timestamps. Collection columns are lists, sets, or maps that can be atomically updated.
All varieties of column have a type; see Type for the full list of possibilities. A collection column’s type is the type of its elements (in the case of a map collection, there is both a key type and a value type).
Defined Under Namespace
Modules: ClassMethods, ConstructorMethods
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
True if this record has the same type and key attributes as the other record.
-
#[](column_name) ⇒ Object
Read an attribute.
-
#[]=(column_name, value) ⇒ void
Write an attribute.
-
#attribute_names ⇒ Array<Symbol>
List of names of attributes on this record.
-
#attributes ⇒ Hash<String,Object>
Map of column names to values currently set on this record.
-
#attributes=(attributes) ⇒ void
Set attributes on the record.
- #initialize(attributes = {}, record_collection = nil) ⇒ Object
-
#inspect ⇒ String
String representation of the record.
Instance Method Details
#==(other) ⇒ Boolean
Returns true if this record has the same type and key attributes as the other record.
346 347 348 349 350 351 352 |
# File 'lib/cequel/record/properties.rb', line 346 def ==(other) if key_values.any? { |value| value.nil? } super else self.class == other.class && key_values == other.key_values end end |
#[](column_name) ⇒ Object
Read an attribute
327 328 329 |
# File 'lib/cequel/record/properties.rb', line 327 def [](column_name) read_attribute(column_name) end |
#[]=(column_name, value) ⇒ void
This method returns an undefined value.
Write an attribute
339 340 341 |
# File 'lib/cequel/record/properties.rb', line 339 def []=(column_name, value) write_attribute(column_name, value) end |
#attribute_names ⇒ Array<Symbol>
Returns list of names of attributes on this record.
291 292 293 |
# File 'lib/cequel/record/properties.rb', line 291 def attribute_names @attributes.keys end |
#attributes ⇒ Hash<String,Object>
Returns map of column names to values currently set on this record.
299 300 301 302 303 304 |
# File 'lib/cequel/record/properties.rb', line 299 def attributes attribute_names .each_with_object(HashWithIndifferentAccess.new) do |name, attributes| attributes[name] = read_attribute(name) end end |
#attributes=(attributes) ⇒ void
This method returns an undefined value.
Set attributes on the record. Each attribute is set via the setter method; virtual (non-column) attributes are allowed.
313 314 315 316 317 |
# File 'lib/cequel/record/properties.rb', line 313 def attributes=(attributes) attributes.each_pair do |attribute, value| __send__(:"#{attribute}=", value) end end |
#initialize(attributes = {}, record_collection = nil) ⇒ Object
283 284 285 286 |
# File 'lib/cequel/record/properties.rb', line 283 def initialize(attributes = {}, record_collection = nil) @attributes, @record_collection = attributes, record_collection @collection_proxies = {} end |
#inspect ⇒ String
Returns string representation of the record.
357 358 359 360 361 362 363 364 365 |
# File 'lib/cequel/record/properties.rb', line 357 def inspect inspected_attributes = attributes.each_pair.map do |attr, value| inspected_value = Cequel.uuid?(value) ? value.to_s : value.inspect "#{attr}: #{inspected_value}" end "#<#{self.class} #{inspected_attributes.join(", ")}>" end |