Class: Cequel::Schema::Column Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/cequel/schema/column.rb

Overview

This class is abstract.

Represents a column definition in a table schema.

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type) ⇒ Column

Returns a new instance of Column.

Parameters:

  • name (Symbol)

    the name of the column

  • type (Type)

    the type of the column

Since:

  • 1.0.0


19
20
21
# File 'lib/cequel/schema/column.rb', line 19

def initialize(name, type)
  @name, @type = name, type
end

Instance Attribute Details

#nameSymbol (readonly)

Returns the name of the column.

Returns:

  • (Symbol)

    the name of the column

Since:

  • 1.0.0


11
12
13
# File 'lib/cequel/schema/column.rb', line 11

def name
  @name
end

#typeType (readonly)

Returns the type of the column.

Returns:

  • (Type)

    the type of the column

Since:

  • 1.0.0


13
14
15
# File 'lib/cequel/schema/column.rb', line 13

def type
  @type
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Returns true if this column has the same CQL representation as `other` column.

Parameters:

  • other (Column)

    a column object

Returns:

  • (Boolean)

    true if this column has the same CQL representation as `other` column

Since:

  • 1.0.0


116
117
118
# File 'lib/cequel/schema/column.rb', line 116

def ==(other)
  to_cql == other.to_cql
end

#cast(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the value cast to the appropriate type for this column.

Parameters:

  • value

    the value to cast

Returns:

  • the value cast to the appropriate type for this column

Since:

  • 1.0.0


97
98
99
# File 'lib/cequel/schema/column.rb', line 97

def cast(value)
  @type.cast(value)
end

#clustering_column?Boolean

Returns true if this is a clustering column.

Returns:

  • (Boolean)

    true if this is a clustering column

See Also:

Since:

  • 1.0.0


54
55
56
# File 'lib/cequel/schema/column.rb', line 54

def clustering_column?
  false
end

#collection_column?Boolean

Returns true if this is a collection column.

Returns:

  • (Boolean)

    true if this is a collection column

Since:

  • 1.0.0


70
71
72
# File 'lib/cequel/schema/column.rb', line 70

def collection_column?
  false
end

#data_column?Boolean

Returns true if this is a data column.

Returns:

  • (Boolean)

    true if this is a data column

Since:

  • 1.0.0


63
64
65
# File 'lib/cequel/schema/column.rb', line 63

def data_column?
  !key?
end

#indexed?Boolean

Indicates if this column is indexed. Overridden by subclasses that support indexing.

Returns:

  • (Boolean)

    true if this column has a secondary index

Since:

  • 1.0.0


79
80
81
# File 'lib/cequel/schema/column.rb', line 79

def indexed?
  false
end

#inspectString

Returns human-readable representation of this column.

Returns:

  • (String)

    human-readable representation of this column

Since:

  • 1.0.0


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

def inspect
  %Q(#<#{self.class.name}: #{to_cql}>)
end

#key?Boolean

Returns true if this is a key column.

Returns:

  • (Boolean)

    true if this is a key column

See Also:

Since:

  • 1.0.0


32
33
34
# File 'lib/cequel/schema/column.rb', line 32

def key?
  partition_key? || clustering_column?
end

#partition_key?Boolean

Returns true if this is a partition key column.

Returns:

  • (Boolean)

    true if this is a partition key column

See Also:

Since:

  • 1.0.0


43
44
45
# File 'lib/cequel/schema/column.rb', line 43

def partition_key?
  false
end

#to_cqlString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a CQL fragment representing this column in a table definition.

Returns:

  • (String)

    a CQL fragment representing this column in a table definition

Since:

  • 1.0.0


107
108
109
# File 'lib/cequel/schema/column.rb', line 107

def to_cql
  %Q|"#{@name}" #{@type}|
end

#to_sString

Returns the column's name.

Returns:

  • (String)

    the column's name

Since:

  • 1.0.0


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

def to_s
  name.to_s
end

#type?(type_in) ⇒ Boolean

Returns true if this column has the type given by `type_in`.

Parameters:

  • type_in (Symbol, Type)

    type to check against

Returns:

  • (Boolean)

    true if this column has the type given by `type_in`

Since:

  • 1.0.0


87
88
89
# File 'lib/cequel/schema/column.rb', line 87

def type?(type_in)
  type == Type[type_in]
end