Class: Cequel::Record::Set

Inherits:
Set
  • Object
show all
Includes:
Collection
Defined in:
lib/cequel/record/collection.rb

Overview

The value of a set column in a Cequel::Record instance. Contains an unordered, unique set of elements. Encapsulates and behaves like the ‘Set` type from the standard library.

See Also:

Since:

  • 1.0.0

Constant Summary collapse

NON_ATOMIC_MUTATORS =

These methods are not implemented because they cannot be expressed as a single CQL3 write operation.

Since:

  • 1.0.0

[
  :add?,
  :collect!,
  :delete?,
  :delete_if,
  :flatten!,
  :keep_if,
  :map!,
  :reject!,
  :select!
]

Instance Method Summary collapse

Methods included from Collection

#column_name, #initialize, #inspect, #loaded!, #loaded?, #persisted!

Instance Method Details

#add(object) ⇒ Set Also known as: <<

Add an element to the set

Parameters:

  • object

    element to add

Returns:

  • (Set)

    self

Since:

  • 1.0.0



369
370
371
372
373
# File 'lib/cequel/record/collection.rb', line 369

def add(object)
  object = cast_element(object)
  updater.set_add(column_name, object)
  to_modify { super }
end

#clearSet

Remove everything from the set. Equivalent to deleting the collection column from the record’s row.

Returns:

  • (Set)

    self

Since:

  • 1.0.0



382
383
384
385
# File 'lib/cequel/record/collection.rb', line 382

def clear
  deleter.delete_columns(column_name)
  to_modify { super }
end

#delete(object) ⇒ Set

Remove a single element from the set

Parameters:

  • object

    element to remove

Returns:

  • (Set)

    self

Since:

  • 1.0.0



393
394
395
396
397
# File 'lib/cequel/record/collection.rb', line 393

def delete(object)
  object = cast_element(object)
  updater.set_remove(column_name, object)
  to_modify { super }
end

#replace(set) ⇒ Set

Replace the entire contents of this set with another set

Parameters:

  • set (::Set)

    set containing new elements

Returns:

  • (Set)

    self

Since:

  • 1.0.0



405
406
407
408
409
# File 'lib/cequel/record/collection.rb', line 405

def replace(set)
  set = cast_collection(set)
  updater.set(column_name => set)
  to_modify { super }
end