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:



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
58
# File 'lib/aerospike/value/value.rb', line 27

def self.of(value)
  case value
  when nil
    res = NullValue.new
  when Integer
    if value < 2**63
      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)
  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