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?, #indexed?, #inspect, #key?, #partition_key?, #to_s, #type?
Constructor Details
#initialize(name, key_type, value_type) ⇒ Map
Returns a new instance of Map.
283 284 285 286 |
# File 'lib/cequel/schema/column.rb', line 283 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.
275 276 277 |
# File 'lib/cequel/schema/column.rb', line 275 def key_type @key_type end |
Instance Method Details
#cast(value) ⇒ Hash
Returns hash with keys and values cast to correct type for column.
298 299 300 301 302 |
# File 'lib/cequel/schema/column.rb', line 298 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.
289 290 291 |
# File 'lib/cequel/schema/column.rb', line 289 def to_cql "#{@name} MAP <#{@key_type}, #{@type}>" end |