Module: Aws::Record::Attributes::ClassMethods
- Included in:
- Aws::Record
- Defined in:
- lib/aws-record/record/attributes.rb
Instance Method Summary collapse
-
#attr(name, marshaler, opts = {}) ⇒ Object
Define an attribute for your model, providing your own attribute type.
- #attributes ⇒ Object private
-
#boolean_attr(name, opts = {}) ⇒ Object
Define a boolean-type attribute for your model.
-
#date_attr(name, opts = {}) ⇒ Object
Define a date-type attribute for your model.
-
#datetime_attr(name, opts = {}) ⇒ Object
Define a datetime-type attribute for your model.
-
#float_attr(name, opts = {}) ⇒ Object
Define a float-type attribute for your model.
-
#hash_key ⇒ Symbol?
The symbolic name of the table’s hash key.
-
#integer_attr(name, opts = {}) ⇒ Object
Define a integer-type attribute for your model.
- #keys ⇒ Object private
-
#list_attr(name, opts = {}) ⇒ Object
Define a list-type attribute for your model.
-
#map_attr(name, opts = {}) ⇒ Object
Define a map-type attribute for your model.
-
#numeric_set_attr(name, opts = {}) ⇒ Object
Define a numeric set attribute for your model.
-
#range_key ⇒ Symbol?
The symbloc name of the table’s range key, or nil if there is no range key.
-
#string_attr(name, opts = {}) ⇒ Object
Define a string-type attribute for your model.
-
#string_set_attr(name, opts = {}) ⇒ Object
Define a string set attribute for your model.
-
#time_attr(name, opts = {}) ⇒ Object
Define a time-type attribute for your model.
Instance Method Details
#attr(name, marshaler, opts = {}) ⇒ Object
Define an attribute for your model, providing your own attribute type.
90 91 92 93 94 |
# File 'lib/aws-record/record/attributes.rb', line 90 def attr(name, marshaler, opts = {}) @attributes.register_attribute(name, marshaler, opts) _define_attr_methods(name) _key_attributes(name, opts) end |
#attributes ⇒ 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.
374 375 376 |
# File 'lib/aws-record/record/attributes.rb', line 374 def attributes @attributes end |
#boolean_attr(name, opts = {}) ⇒ Object
Define a boolean-type attribute for your model.
133 134 135 136 |
# File 'lib/aws-record/record/attributes.rb', line 133 def boolean_attr(name, opts = {}) opts[:dynamodb_type] = "BOOL" attr(name, Marshalers::BooleanMarshaler.new(opts), opts) end |
#date_attr(name, opts = {}) ⇒ Object
Define a date-type attribute for your model.
196 197 198 199 |
# File 'lib/aws-record/record/attributes.rb', line 196 def date_attr(name, opts = {}) opts[:dynamodb_type] = "S" attr(name, Marshalers::DateMarshaler.new(opts), opts) end |
#datetime_attr(name, opts = {}) ⇒ Object
Define a datetime-type attribute for your model.
217 218 219 220 |
# File 'lib/aws-record/record/attributes.rb', line 217 def datetime_attr(name, opts = {}) opts[:dynamodb_type] = "S" attr(name, Marshalers::DateTimeMarshaler.new(opts), opts) end |
#float_attr(name, opts = {}) ⇒ Object
Define a float-type attribute for your model.
175 176 177 178 |
# File 'lib/aws-record/record/attributes.rb', line 175 def float_attr(name, opts = {}) opts[:dynamodb_type] = "N" attr(name, Marshalers::FloatMarshaler.new(opts), opts) end |
#hash_key ⇒ Symbol?
Returns The symbolic name of the table’s hash key.
364 365 366 |
# File 'lib/aws-record/record/attributes.rb', line 364 def hash_key @keys.hash_key end |
#integer_attr(name, opts = {}) ⇒ Object
Define a integer-type attribute for your model.
154 155 156 157 |
# File 'lib/aws-record/record/attributes.rb', line 154 def integer_attr(name, opts = {}) opts[:dynamodb_type] = "N" attr(name, Marshalers::IntegerMarshaler.new(opts), opts) end |
#keys ⇒ 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.
379 380 381 |
# File 'lib/aws-record/record/attributes.rb', line 379 def keys @keys.keys end |
#list_attr(name, opts = {}) ⇒ Object
Define a list-type attribute for your model.
Lists do not have to be homogeneous, but they do have to be types that the AWS SDK for Ruby V2’s DynamoDB client knows how to marshal and unmarshal. Those types are:
-
Hash
-
Array
-
String
-
Numeric
-
Boolean
-
IO
-
Set
-
nil
Also note that, since lists are heterogeneous, you may lose some precision when marshaling and unmarshaling. For example, symbols will be stringified, but there is no way to return those strings to symbols when the object is read back from DynamoDB.
273 274 275 276 |
# File 'lib/aws-record/record/attributes.rb', line 273 def list_attr(name, opts = {}) opts[:dynamodb_type] = "L" attr(name, Marshalers::ListMarshaler.new(opts), opts) end |
#map_attr(name, opts = {}) ⇒ Object
Define a map-type attribute for your model.
Maps do not have to be homogeneous, but they do have to use types that the AWS SDK for Ruby V2’s DynamoDB client knows how to marshal and unmarshal. Those types are:
-
Hash
-
Array
-
String
-
Numeric
-
Boolean
-
IO
-
Set
-
nil
Also note that, since maps are heterogeneous, you may lose some precision when marshaling and unmarshaling. For example, symbols will be stringified, but there is no way to return those strings to symbols when the object is read back from DynamoDB.
308 309 310 311 |
# File 'lib/aws-record/record/attributes.rb', line 308 def map_attr(name, opts = {}) opts[:dynamodb_type] = "M" attr(name, Marshalers::MapMarshaler.new(opts), opts) end |
#numeric_set_attr(name, opts = {}) ⇒ Object
Define a numeric set attribute for your model.
Numeric sets are homogeneous sets, containing only numbers. Note that empty sets cannot be persisted to DynamoDB. Empty sets are valid for aws-record items, but they will not be persisted as sets. nil values from your table, or a lack of value from your table, will be treated as an empty set for item instances. At persistence time, the marshaler will attempt to marshal any non-numerics within the set to be Numeric objects.
358 359 360 361 |
# File 'lib/aws-record/record/attributes.rb', line 358 def numeric_set_attr(name, opts = {}) opts[:dynamodb_type] = "NS" attr(name, Marshalers::NumericSetMarshaler.new(opts), opts) end |
#range_key ⇒ Symbol?
Returns The symbloc name of the table’s range key, or nil if there is no range key.
369 370 371 |
# File 'lib/aws-record/record/attributes.rb', line 369 def range_key @keys.range_key end |
#string_attr(name, opts = {}) ⇒ Object
Define a string-type attribute for your model.
112 113 114 115 |
# File 'lib/aws-record/record/attributes.rb', line 112 def string_attr(name, opts = {}) opts[:dynamodb_type] = "S" attr(name, Marshalers::StringMarshaler.new(opts), opts) end |
#string_set_attr(name, opts = {}) ⇒ Object
Define a string set attribute for your model.
String sets are homogeneous sets, containing only strings. Note that empty sets cannot be persisted to DynamoDB. Empty sets are valid for aws-record items, but they will not be persisted as sets. nil values from your table, or a lack of value from your table, will be treated as an empty set for item instances. At persistence time, the marshaler will attempt to marshal any non-strings within the set to be String objects.
333 334 335 336 |
# File 'lib/aws-record/record/attributes.rb', line 333 def string_set_attr(name, opts = {}) opts[:dynamodb_type] = "SS" attr(name, Marshalers::StringSetMarshaler.new(opts), opts) end |
#time_attr(name, opts = {}) ⇒ Object
Define a time-type attribute for your model.
238 239 240 241 |
# File 'lib/aws-record/record/attributes.rb', line 238 def time_attr(name, opts = {}) opts[:dynamodb_type] = "S" attr(name, Marshalers::TimeMarshaler.new(opts), opts) end |