Class: Cequel::Record::Map

Inherits:
Hash
  • Object
show all
Extended by:
Util::Forwardable
Includes:
Collection
Defined in:
lib/cequel/record/collection.rb

Overview

The value of a ‘map` column in a Cequel::Record instance. Encapsulates and behaves like a built-in `Hash`.

See Also:

Since:

  • 1.0.0

Constant Summary collapse

NON_ATOMIC_MUTATORS =

These methods involve mutation that cannot be expressed as a CQL operation, so are not implemented.

Since:

  • 1.0.0

[
  :default,
  :default=,
  :default_proc,
  :default_proc=,
  :delete_if,
  :deep_merge!,
  :except!,
  :extract!,
  :keep_if,
  :reject!,
  :reverse_merge!,
  :reverse_update,
  :select!,
  :shift,
  :slice!,
  :stringify_keys!,
  :symbolize_keys!,
  :to_options!,
  :transform_keys!
]

Instance Method Summary collapse

Methods included from Util::Forwardable

delegate

Methods included from Collection

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

Instance Method Details

#[]=(key, value) ⇒ Map Also known as: store

Set the value of a given key

Parameters:

  • key

    the key

  • value

    the value

Returns:

  • (Map)

    self

Since:

  • 1.0.0



464
465
466
467
468
# File 'lib/cequel/record/collection.rb', line 464

def []=(key, value)
  key = cast_key(key)
  to_update { updater.map_update(column_name, key => value) }
  to_modify { super }
end

#clearMap

Remove all elements from this map. Equivalent to deleting the column value from the row in CQL

Returns:

  • (Map)

    self

Since:

  • 1.0.0



477
478
479
480
# File 'lib/cequel/record/collection.rb', line 477

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

#delete(key) ⇒ Map

Delete one key from the map

Parameters:

  • key

    the key to delete

Returns:

  • (Map)

    self

Since:

  • 1.0.0



488
489
490
491
492
# File 'lib/cequel/record/collection.rb', line 488

def delete(key)
  key = cast_key(key)
  to_update { deleter.map_remove(column_name, key) }
  to_modify { super }
end

#merge!(hash) ⇒ Map Also known as: update

Update a collection of keys and values given by a hash

Parameters:

  • hash (Hash)

    hash containing keys and values to set

Returns:

  • (Map)

    self

Since:

  • 1.0.0



500
501
502
503
504
# File 'lib/cequel/record/collection.rb', line 500

def merge!(hash)
  hash = cast_collection(hash)
  to_update { updater.map_update(column_name, hash) }
  to_modify { super }
end

#replace(hash) ⇒ Map

Replace the entire contents of this map with a new one

Parameters:

  • hash (Hash)

    hash containing new keys and values

Returns:

  • (Map)

    self

Since:

  • 1.0.0



513
514
515
516
517
# File 'lib/cequel/record/collection.rb', line 513

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