17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/ocean-dynamo/attributes.rb', line 17
def dynamo_schema(table_hash_key=:id,
table_range_key=nil,
locking: :lock_version,
timestamps: [:created_at, :updated_at],
**keywords,
&block)
self.lock_attribute = locking
self.timestamp_attributes = timestamps
self.fields = HashWithIndifferentAccess.new
attribute(table_hash_key, :string, default: "")
self.global_secondary_indexes = Hash.new
if table_range_key
attribute(table_range_key, :string, default: "")
self.validates(table_range_key, presence: true)
end
timestamp_attributes.each { |name| attribute name, :datetime } if timestamp_attributes
attribute(lock_attribute, :integer, default: 0) if locking
block.call
fields.each { |name, md| define_attribute_accessors(name) }
super
end
|