Module: Cequel::Record::Collection Abstract
- Extended by:
- ActiveSupport::Concern, Util::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.
Methods included from Util::Forwardable
Instance Method Details
#column_name ⇒ Symbol
Returns the name of the collection column.
70 |
# File 'lib/cequel/record/collection.rb', line 70 def_delegator :@column, :name, :column_name |
#initialize(model, column) ⇒ Collection
Returns a new collection.
86 87 88 |
# File 'lib/cequel/record/collection.rb', line 86 def initialize(model, column) @model, @column = model, column end |
#inspect ⇒ String
Returns inspected underlying Ruby collection object.
93 94 95 |
# File 'lib/cequel/record/collection.rb', line 93 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.
104 105 106 |
# File 'lib/cequel/record/collection.rb', line 104 def loaded! modifications.each { |modification| modification.call() }.clear end |
#loaded? ⇒ Boolean
Returns ‘true` if the collection’s contents are loaded into memory.
63 |
# File 'lib/cequel/record/collection.rb', line 63 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.
116 117 118 |
# File 'lib/cequel/record/collection.rb', line 116 def persisted! modifications.clear end |