Class: Cassandra::Types::Map

Inherits:
Cassandra::Type show all
Defined in:
lib/cassandra/types.rb

Instance Method Summary collapse

Instance Method Details

#assert(value, message = nil, &block) ⇒ void

This method returns an undefined value.

Asserts that a given value is a Hash

Parameters:

  • value (Object)

    value to be validated

  • message (String) (defaults to: nil)

    error message to use when assertion fails

Yield Returns:

  • (String)

    error message to use when assertion fails

Raises:

  • (ArgumentError)

    if the value is not a Hash

See Also:



829
830
831
832
833
834
835
836
# File 'lib/cassandra/types.rb', line 829

def assert(value, message = nil, &block)
  Util.assert_instance_of(::Hash, value, message, &block)
  value.each do |k, v|
    Util.assert_type(@key_type, k, message, &block)
    Util.assert_type(@value_type, v, message, &block)
  end
  nil
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:



844
845
846
847
848
# File 'lib/cassandra/types.rb', line 844

def eql?(other)
  other.is_a?(Map) &&
    @key_type == other.key_type &&
    @value_type == other.value_type
end

#kindSymbol

Returns :map.

Returns:

  • (Symbol)

    :map

See Also:



791
792
793
# File 'lib/cassandra/types.rb', line 791

def kind
  :map
end

#new(*value) ⇒ Hash

Coerces the value to Hash

Parameters:

  • value (Object)

    original value

Returns:

  • (Hash)

    value

See Also:



799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
# File 'lib/cassandra/types.rb', line 799

def new(*value)
  value = value.first if value.one?

  case value
  when ::Hash
    value.each do |k, v|
      Util.assert_type(@key_type, k)
      Util.assert_type(@value_type, v)
    end
    value
  when ::Array
    result = ::Hash.new
    value.each_slice(2) do |(k, v)|
      Util.assert_type(@key_type, k)
      Util.assert_type(@value_type, v)
      result[k] = v
    end
    result
  else
    raise ::ArgumentError, "cannot convert #{value.inspect} to #{to_s}"
  end
end

#to_sString

Returns "map<type, type>".

Returns:

  • (String)

    "map<type, type>"

See Also:



840
841
842
# File 'lib/cassandra/types.rb', line 840

def to_s
  "map<#{@key_type.to_s}, #{@value_type.to_s}>"
end