Class: DatastaxRails::Types::DynamicMap

Inherits:
ActiveSupport::HashWithIndifferentAccess
  • Object
show all
Includes:
DirtyCollection
Defined in:
lib/datastax_rails/types/dynamic_map.rb

Overview

A collection type that allows you to store key/value pairs in Cassandra. Changes are tracked by hooking into ActiveModel’s built-in change tracking.

Keys are converted to have the name of the collection prefixed to them as this is how the Solr/Cassandra integration converts between them and dynamic fields.

Instance Method Summary collapse

Methods included from DirtyCollection

#delete, ignore_modifications, #initialize

Instance Method Details

#[](key) ⇒ Object



19
20
21
# File 'lib/datastax_rails/types/dynamic_map.rb', line 19

def [](key)
  super(convert_key(key))
end

#convert_key(key) ⇒ Object



23
24
25
26
# File 'lib/datastax_rails/types/dynamic_map.rb', line 23

def convert_key(key)
  key = name + key.to_s unless key.to_s.starts_with?(name)
  super(key)
end

#dupObject



13
14
15
16
17
# File 'lib/datastax_rails/types/dynamic_map.rb', line 13

def dup
  self.class.new(record, name, self).tap do |new_hash|
    new_hash.default = default
  end
end