Module: Cequel::Record::Collection Abstract
- Extended by:
- ActiveSupport::Concern, Forwardable
- Defined in:
- lib/cequel/record/collection.rb
Overview
Including classes must descend from ‘Delegator` and implement the `::empty` class method.
The value of a collection column in a Cequel::Record. Collections track modifications that can be expressed as atomic collection mutations in CQL, and persist those modifications when their owning record is saved. Such modifications can be done even if the collection has not loaded data from CQL, in the case of an unloaded record or where the collection column was not included in the ‘SELECT` statement.
Mutation operations that require reading data before writing it are not supported (e.g. ‘Array#map!).
Each collection implementation wraps a built-in Ruby collection type.
Instance Method Summary collapse
-
#column_name ⇒ Symbol
The name of the collection column.
-
#initialize(model, column) ⇒ Collection
A new collection.
-
#inspect ⇒ String
Inspected underlying Ruby collection object.
-
#loaded! ⇒ void
private
Notify the collection that its underlying data is loaded in memory.
-
#loaded? ⇒ Boolean
‘true` if the collection’s contents are loaded into memory.
-
#persisted! ⇒ void
private
Notify the collection that its staged changes have been written to the data store.
Instance Method Details
#column_name ⇒ Symbol
Returns the name of the collection column.
69 |
# File 'lib/cequel/record/collection.rb', line 69 def_delegator :@column, :name, :column_name |
#initialize(model, column) ⇒ Collection
Returns a new collection.
85 86 87 |
# File 'lib/cequel/record/collection.rb', line 85 def initialize(model, column) @model, @column = model, column end |
#inspect ⇒ String
Returns inspected underlying Ruby collection object.
92 93 94 |
# File 'lib/cequel/record/collection.rb', line 92 def inspect __getobj__.inspect end |
#loaded! ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Notify the collection that its underlying data is loaded in memory.
103 104 105 |
# File 'lib/cequel/record/collection.rb', line 103 def loaded! modifications.each { |modification| modification.call() }.clear end |
#loaded? ⇒ Boolean
Returns ‘true` if the collection’s contents are loaded into memory.
62 |
# File 'lib/cequel/record/collection.rb', line 62 def_delegators :@model, :loaded?, :updater, :deleter |
#persisted! ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Notify the collection that its staged changes have been written to the data store.
115 116 117 |
# File 'lib/cequel/record/collection.rb', line 115 def persisted! modifications.clear end |