Module: DynaModel::Document
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveModel::Conversion, ActiveModel::MassAssignmentSecurity, ActiveModel::Naming, ActiveModel::Observing, ActiveModel::Serializers::JSON, ActiveModel::Serializers::Xml, Attributes, Query, Schema
- Defined in:
- lib/dyna_model/document.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary
collapse
- MAX_ITEM_SIZE =
65_536
- GUID_DELIMITER_PRECEDENCE =
These delimiters are also reserved characters and should not be used in hash or range keys
["_", ":", "|", ",", "!", "~", "@", "^"]
Constants included
from Query
Query::DEFAULT_BATCH_SIZE, Query::QUERY_TIMEOUT
Instance Method Summary
collapse
Instance Method Details
#all_attributes_loaded? ⇒ Boolean
90
91
92
|
# File 'lib/dyna_model/document.rb', line 90
def all_attributes_loaded?
self.instance_variable_get("@_select").nil? && self.instance_variable_get("@_select") == :all
end
|
#dynamo_db_guid ⇒ Object
78
79
80
81
82
|
# File 'lib/dyna_model/document.rb', line 78
def dynamo_db_guid
_guid = [self.dynamo_db_item_key_values[:hash_value]]
_guid << self.dynamo_db_item_key_values[:range_value] if self.dynamo_db_item_key_values[:range_value]
_guid.join(self.class.guid_delimiter)
end
|
#dynamo_db_item_key_values ⇒ Object
84
85
86
87
88
|
# File 'lib/dyna_model/document.rb', line 84
def dynamo_db_item_key_values
key_values = { hash_value: self[self.class.hash_key[:attribute_name]] }
key_values.merge!(range_value: self[self.class.range_key[:attribute_name]]) if self.class.range_key
key_values
end
|
#id ⇒ Object
70
71
72
|
# File 'lib/dyna_model/document.rb', line 70
def id
self.dynamo_db_guid
end
|
#load_attributes! ⇒ Object
When only partial attributes were selected (via GSI or projected attributes on an index)
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/dyna_model/document.rb', line 95
def load_attributes!
raise "All attributes already loaded!" if self.instance_variable_get("@_select") == :all
options = { shard_name: self.shard }
if self.class.range_key
obj = self.class.read(dynamo_db_item_key_values[:hash_value], dynamo_db_item_key_values[:range_value], options)
else
obj = self.class.read(dynamo_db_item_key_values[:hash_value], options)
end
raise "Could not find object" unless obj
self.instance_variable_set("@_select", :all)
self.remove_instance_variable("@_selected_attributes")
self.instance_variable_set("@_data", obj.instance_variable_get("@_data"))
self
end
|
#to_param ⇒ Object
74
75
76
|
# File 'lib/dyna_model/document.rb', line 74
def to_param
self.dynamo_db_guid
end
|
#touch ⇒ Object
110
111
112
|
# File 'lib/dyna_model/document.rb', line 110
def touch
self.send(:touch_timestamps, "updated_at")
end
|
#touch! ⇒ Object
114
115
116
117
|
# File 'lib/dyna_model/document.rb', line 114
def touch!
self.touch
self.save
end
|