Class: Cequel::Type::Base Abstract

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/cequel/type.rb

Overview

This class is abstract.

Subclasses should implement #cast, and may implement #internal_names if it cannot be inferred from the class name. The name of the type class should be the camel-cased CQL name of the type

The base class for all type objects. Types are singletons.

Since:

  • 1.0.0

Direct Known Subclasses

Boolean, Counter, Date, Decimal, Double, Inet, Int, String, Timestamp, Uuid

Instance Method Summary collapse

Instance Method Details

#cast(value) ⇒ Object

Returns the value cast to the correct Ruby class for this type.

Parameters:

  • value

    the value to cast

Returns:

  • the value cast to the correct Ruby class for this type

Since:

  • 1.0.0



158
159
160
# File 'lib/cequel/type.rb', line 158

def cast(value)
  value
end

#compatible_typesArray<Type>

CQL only allows changing column types when the old type’s binary representation is compatible with the new type.

Returns:

  • (Array<Type>)

    new types that columns of this type may be altered to

Since:

  • 1.0.0



169
170
171
# File 'lib/cequel/type.rb', line 169

def compatible_types
  [Type[:blob]]
end

#cql_aliasesArray<Symbol>

Returns other names used in CQL for this type.

Returns:

  • (Array<Symbol>)

    other names used in CQL for this type

Since:

  • 1.0.0



131
132
133
# File 'lib/cequel/type.rb', line 131

def cql_aliases
  []
end

#cql_nameObject

Returns the name of the type used in CQL. This is also the name that is used in all of Cequel’s public interfaces.

Returns:

  • the name of the type used in CQL. This is also the name that is used in all of Cequel’s public interfaces

Since:

  • 1.0.0



124
125
126
# File 'lib/cequel/type.rb', line 124

def cql_name
  self.class.name.demodulize.underscore.to_sym
end

#internal_nameArray<String>

Deprecated.

Returns full class name of this type used in Cassandra’s underlying representation.

Returns:

  • (Array<String>)

    full class name of this type used in Cassandra’s underlying representation

Since:

  • 1.0.0



141
142
143
# File 'lib/cequel/type.rb', line 141

def internal_name
  internal_names.first
end

#internal_namesArray<String>

Returns full class name(s) of this type used in Cassandra’s underlying representation (allows for multiple values for types that have different names between different versions).

Returns:

  • (Array<String>)

    full class name(s) of this type used in Cassandra’s underlying representation (allows for multiple values for types that have different names between different versions)

Since:

  • 1.0.0



150
151
152
# File 'lib/cequel/type.rb', line 150

def internal_names
  ["org.apache.cassandra.db.marshal.#{self.class.name.demodulize}Type"]
end

#to_sObject

A string representation of this type

Since:

  • 1.0.0



176
177
178
# File 'lib/cequel/type.rb', line 176

def to_s
  cql_name.to_s
end