Class: Cequel::Schema::Map

Inherits:
CollectionColumn show all
Defined in:
lib/cequel/schema/column.rb

Overview

A Map column

See Also:

Since:

  • 1.0.0

Instance Attribute Summary collapse

Attributes inherited from Column

#name, #type

Instance Method Summary collapse

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.

Parameters:

  • name (Symbol)

    name of this column

  • key_type (Type)

    type of the keys in the map

  • value_type (Type)

    type of the values in the map

Since:

  • 1.0.0


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_typeType (readonly)

Returns the type of keys in this map.

Returns:

  • (Type)

    the type of keys in this map

Since:

  • 1.0.0


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.

Parameters:

  • value

    the value to cast

Returns:

  • (Hash)

    hash with keys and values cast to correct type for column

Since:

  • 1.0.0


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_cqlString

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.

Returns:

  • (String)

    a CQL fragment representing this column in a table definition

Since:

  • 1.0.0


289
290
291
# File 'lib/cequel/schema/column.rb', line 289

def to_cql
  "#{@name} MAP <#{@key_type}, #{@type}>"
end