Sha256: e214e895de6a444d673693eeba75ebb41e82fbcc2309d5c9a31fa246c74a652c
Contents?: true
Size: 1.65 KB
Versions: 3
Compression:
Stored size: 1.65 KB
Contents
module CassandraObject module Types class TypeHelper def self.guess_type(object) case object when ::String then Cassandra::Types.varchar when ::Fixnum then Cassandra::Types.int when ::Integer then Cassandra::Types.int when ::Float then Cassandra::Types.float when ::Bignum then Cassandra::Types.varint when ::BigDecimal then Cassandra::Types.decimal when ::TrueClass then Cassandra::Types.boolean when ::FalseClass then Cassandra::Types.boolean when ::NilClass then Cassandra::Types.bigint # when Uuid then Cassandra::Types.uuid # when TimeUuid then Cassandra::Types.timeuuid when ::IPAddr then Cassandra::Types.inet when ::Time then Cassandra::Types.timestamp when ::Hash pair = object.first Types.map(guess_type(pair[0]), guess_type(pair[1])) when ::Array then Types.list(guess_type(object.first)) when ::Set then Types.set(guess_type(object.first)) # when Tuple::Strict then Types.tuple(*object.types) # when Tuple then Types.tuple(*object.map {|v| guess_type(v)}) # when UDT::Strict # Types.udt(object.keyspace, object.name, object.types) # when UDT # Types.udt('unknown', 'unknown', object.map {|k, v| [k, guess_type(v)]}) when Cassandra::CustomData then object.class.type else raise ::ArgumentError, "Unable to guess the type of the argument: #{object.inspect}" end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems