Class: Cequel::Schema::Column Abstract
- Inherits:
-
Object
- Object
- Cequel::Schema::Column
- Defined in:
- lib/cequel/schema/column.rb
Overview
Represents a column definition in a table schema.
Direct Known Subclasses
ClusteringColumn, CollectionColumn, DataColumn, PartitionKey
Instance Attribute Summary collapse
-
#name ⇒ Symbol
readonly
The name of the column.
-
#type ⇒ Type
readonly
The type of the column.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
True if this column has the same CQL representation as ‘other` column.
-
#cast(value) ⇒ Object
private
The value cast to the appropriate type for this column.
-
#clustering_column? ⇒ Boolean
True if this is a clustering column.
-
#collection_column? ⇒ Boolean
True if this is a collection column.
-
#data_column? ⇒ Boolean
True if this is a data column.
-
#initialize(name, type) ⇒ Column
constructor
A new instance of Column.
-
#inspect ⇒ String
Human-readable representation of this column.
-
#key? ⇒ Boolean
True if this is a key column.
-
#partition_key? ⇒ Boolean
True if this is a partition key column.
-
#to_cql ⇒ String
private
A CQL fragment representing this column in a table definition.
-
#to_s ⇒ String
The column’s name.
-
#type?(type_in) ⇒ Boolean
True if this column has the type given by ‘type_in`.
Constructor Details
#initialize(name, type) ⇒ Column
Returns a new instance of Column.
19 20 21 |
# File 'lib/cequel/schema/column.rb', line 19 def initialize(name, type) @name, @type = name, type end |
Instance Attribute Details
#name ⇒ Symbol (readonly)
Returns the name of the column.
11 12 13 |
# File 'lib/cequel/schema/column.rb', line 11 def name @name end |
#type ⇒ Type (readonly)
Returns the type of the column.
13 14 15 |
# File 'lib/cequel/schema/column.rb', line 13 def type @type end |
Instance Method Details
#==(other) ⇒ Boolean
Returns true if this column has the same CQL representation as ‘other` column.
107 108 109 |
# File 'lib/cequel/schema/column.rb', line 107 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.
88 89 90 |
# File 'lib/cequel/schema/column.rb', line 88 def cast(value) @type.cast(value) end |
#clustering_column? ⇒ Boolean
Returns true if this is a clustering column.
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.
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.
63 64 65 |
# File 'lib/cequel/schema/column.rb', line 63 def data_column? !key? end |
#inspect ⇒ String
Returns human-readable representation of this column.
121 122 123 |
# File 'lib/cequel/schema/column.rb', line 121 def inspect %Q(#<#{self.class.name}: #{to_cql}>) end |
#key? ⇒ Boolean
Returns true if this is a key column.
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.
43 44 45 |
# File 'lib/cequel/schema/column.rb', line 43 def partition_key? false end |
#to_cql ⇒ String
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.
98 99 100 |
# File 'lib/cequel/schema/column.rb', line 98 def to_cql "#{@name} #{@type}" end |
#to_s ⇒ String
Returns the column’s name.
114 115 116 |
# File 'lib/cequel/schema/column.rb', line 114 def to_s name.to_s end |
#type?(type_in) ⇒ Boolean
Returns true if this column has the type given by ‘type_in`.
78 79 80 |
# File 'lib/cequel/schema/column.rb', line 78 def type?(type_in) type == Type[type_in] end |