Class: Cequel::Schema::Map
- Inherits:
-
CollectionColumn
- Object
- Column
- CollectionColumn
- Cequel::Schema::Map
- Defined in:
- lib/cequel/schema/column.rb
Overview
A Map column
Instance Attribute Summary collapse
-
#key_type ⇒ Type
readonly
The type of keys in this map.
Attributes inherited from Column
Instance Method Summary collapse
-
#cast(value) ⇒ Hash
Hash with keys and values cast to correct type for column.
-
#initialize(name, key_type, value_type) ⇒ Map
constructor
A new instance of Map.
-
#to_cql ⇒ String
private
A CQL fragment representing this column in a table definition.
Methods inherited from CollectionColumn
#collection_column?, #indexed?
Methods inherited from Column
#==, #clustering_column?, #collection_column?, #data_column?, #inspect, #key?, #partition_key?, #to_s, #type?
Constructor Details
#initialize(name, key_type, value_type) ⇒ Map
Returns a new instance of Map.
273 274 275 276 |
# File 'lib/cequel/schema/column.rb', line 273 def initialize(name, key_type, value_type) super(name, value_type) @key_type = key_type end |
Instance Attribute Details
#key_type ⇒ Type (readonly)
Returns the type of keys in this map.
265 266 267 |
# File 'lib/cequel/schema/column.rb', line 265 def key_type @key_type end |
Instance Method Details
#cast(value) ⇒ Hash
Returns hash with keys and values cast to correct type for column.
288 289 290 291 292 |
# File 'lib/cequel/schema/column.rb', line 288 def cast(value) value.each_with_object({}) do |(key, element), hash| hash[@key_type.cast(key)] = @type.cast(element) end end |
#to_cql ⇒ String
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.
Returns a CQL fragment representing this column in a table definition.
279 280 281 |
# File 'lib/cequel/schema/column.rb', line 279 def to_cql "#{@name} MAP <#{@key_type}, #{@type}>" end |