Class: Aerospike::Value

Inherits:
Object
  • Object
show all
Defined in:
lib/aerospike/value/value.rb

Overview

Polymorphic value classes used to efficiently serialize objects into the wire protocol.

Class Method Summary collapse

Class Method Details

.of(value) ⇒ Object

:nodoc:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/aerospike/value/value.rb', line 26

def self.of(value)
  case value
  when Integer
    if value.bit_length < 64
      res = IntegerValue.new(value)
    else
      # big nums > 2**63 are not supported
      raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::TYPE_NOT_SUPPORTED, "Value type #{value.class} not supported.")
    end
  when Float
    res = FloatValue.new(value)
  when String
    res = StringValue.new(value)
  when Symbol
    res = StringValue.new(value.to_s)
  when Value
    res = value
  when Hash
    res = MapValue.new(value)
  when Array
    res = ListValue.new(value)
  when GeoJSON
    res = GeoJSONValue.new(value)
  when nil
    res = NULL
  else
    # throw an exception for anything that is not supported.
    raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::TYPE_NOT_SUPPORTED, "Value type #{value.class} not supported.")
  end

  res
end

.validate_hash_key(value) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/aerospike/value/value.rb', line 59

def self.validate_hash_key(value)
  case value
  when Integer
    if value.bit_length >= 64
      raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::TYPE_NOT_SUPPORTED, "Value type #{value.class} not supported as hash key.")
    end
  when Float
  when String
  when Symbol
  when nil
  else
    # throw an exception for anything that is not supported.
    raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::TYPE_NOT_SUPPORTED, "Value type #{value.class} not supported as hash key.")
  end
end