Class: Aerospike::Value
- Inherits:
-
Object
- Object
- Aerospike::Value
- Defined in:
- lib/aerospike/value/value.rb
Overview
Polymorphic value classes used to efficiently serialize objects into the wire protocol.
Direct Known Subclasses
BytesValue, FloatValue, GeoJSONValue, IntegerValue, ListValue, MapValue, NullValue, StringValue
Constant Summary collapse
- INTEGER_RANGE =
:nodoc:
Range.new(-2**63, 2**63 - 1).freeze
Class Method Summary collapse
Class Method Details
.of(value) ⇒ Object
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 INTEGER_RANGE.cover?(value) 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 |