Module: Cequel::Record::Properties::ClassMethods
- Defined in:
- lib/cequel/record/properties.rb
Overview
Methods for defining columns on a record
Instance Method Summary collapse
-
#column(name, type, options = {}) ⇒ void
Define a data column.
-
#key(name, type, options = {}) ⇒ void
Define a key column.
-
#list(name, type, options = {}) ⇒ void
Define a list column.
-
#map(name, key_type, value_type, options = {}) ⇒ void
Define a map column.
-
#set(name, type, options = {}) ⇒ void
Define a set column.
Instance Method Details
#column(name, type, options = {}) ⇒ void
This method returns an undefined value.
Define a data column
120 121 122 123 |
# File 'lib/cequel/record/properties.rb', line 120 def column(name, type, = {}) def_accessors(name) set_attribute_default(name, [:default]) end |
#key(name, type, options = {}) ⇒ void
Note:
belongs_to implicitly defines key columns.
This method returns an undefined value.
Define a key column. By default, the first key column defined for a record will be a partition key, and the following keys will be clustering columns. This behavior can be changed using the ‘:partition` option
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/cequel/record/properties.rb', line 97 def key(name, type, = {}) def_accessors(name) if .fetch(:auto, false) unless Type[type].is_a?(Cequel::Type::Uuid) fail ArgumentError, ":auto option only valid for UUID columns" end default = -> { CassandraCQL::UUID.new } if [:auto] end set_attribute_default(name, default) end |
#list(name, type, options = {}) ⇒ void
This method returns an undefined value.
Define a list column
138 139 140 141 |
# File 'lib/cequel/record/properties.rb', line 138 def list(name, type, = {}) def_collection_accessors(name, List) set_attribute_default(name, .fetch(:default, [])) end |
#map(name, key_type, value_type, options = {}) ⇒ void
This method returns an undefined value.
Define a map column
174 175 176 177 |
# File 'lib/cequel/record/properties.rb', line 174 def map(name, key_type, value_type, = {}) def_collection_accessors(name, Map) set_attribute_default(name, .fetch(:default, {})) end |
#set(name, type, options = {}) ⇒ void
This method returns an undefined value.
Define a set column
156 157 158 159 |
# File 'lib/cequel/record/properties.rb', line 156 def set(name, type, = {}) def_collection_accessors(name, Set) set_attribute_default(name, .fetch(:default, ::Set[])) end |