Module: Cequel::Type
- Defined in:
- lib/cequel/type.rb
Overview
The Type module encapsulates information about the CQL3 type system. Each type has a ‘cql_name`, which is the name of the type as defined in CQL, and an `internal_name`, which is the name of the type in the lower-level interface that is exposed when introspecting table information in the database.
As well as knowing their respective names, types also know how to cast Ruby objects to the correct canonical class corresponding to the type. These implicit types are used by the underlying ‘cassandra-cql` library to determine how to represent values when passing them to Cassandra.
Defined Under Namespace
Classes: Ascii, Base, Bigint, Blob, Boolean, Counter, Decimal, Double, Float, Inet, Int, String, Text, Timestamp, Timeuuid, Uuid, Varint
Constant Summary collapse
- UnknownType =
Raised if an unknown type is looked up
Class.new(ArgumentError)
- BY_CQL_NAME =
{}
- BY_INTERNAL_NAME =
{}
Class Method Summary collapse
-
.[](cql_name) ⇒ Base
Return a type corresponding to the given input.
-
.lookup_cql(cql_name) ⇒ Base
Look up a type by CQL name.
-
.lookup_internal(internal_name) ⇒ Base
Look up a type by internal name.
-
.register(type) ⇒ void
Register a type for lookup.
Class Method Details
.[](cql_name) ⇒ Base
Return a type corresponding to the given input
45 46 47 |
# File 'lib/cequel/type.rb', line 45 def self.[](cql_name) cql_name.is_a?(Base) ? cql_name : lookup_cql(cql_name) end |
.lookup_cql(cql_name) ⇒ Base
Look up a type by CQL name
56 57 58 59 60 |
# File 'lib/cequel/type.rb', line 56 def self.lookup_cql(cql_name) BY_CQL_NAME.fetch(cql_name.to_sym) rescue KeyError raise UnknownType, "Unrecognized CQL type #{cql_name.inspect}" end |
.lookup_internal(internal_name) ⇒ Base
Look up a type by internal name
69 70 71 72 73 |
# File 'lib/cequel/type.rb', line 69 def self.lookup_internal(internal_name) BY_INTERNAL_NAME.fetch(internal_name) rescue KeyError raise UnknownType, "Unrecognized internal type #{internal_name.inspect}" end |
.register(type) ⇒ void
This method returns an undefined value.
Register a type for lookup
31 32 33 34 35 36 37 |
# File 'lib/cequel/type.rb', line 31 def self.register(type) BY_CQL_NAME[type.cql_name] = type type.cql_aliases.each { |aliaz| BY_CQL_NAME[aliaz] = type } type.internal_names.each do |internal_name| BY_INTERNAL_NAME[internal_name] = type end end |