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
- Included in:
- Extensions::Lock
- 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
144
145
146
|
# File 'lib/dyna_model/document.rb', line 144
def all_attributes_loaded?
self.instance_variable_get("@_select").nil? && self.instance_variable_get("@_select") == :all
end
|
#dynamo_db_guid ⇒ Object
132
133
134
135
136
|
# File 'lib/dyna_model/document.rb', line 132
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
138
139
140
141
142
|
# File 'lib/dyna_model/document.rb', line 138
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
124
125
126
|
# File 'lib/dyna_model/document.rb', line 124
def id
self.dynamo_db_guid
end
|
#load_attributes! ⇒ Object
When only partial attributes were selected (via GSI or projected attributes on an index)
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
# File 'lib/dyna_model/document.rb', line 149
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
128
129
130
|
# File 'lib/dyna_model/document.rb', line 128
def to_param
self.dynamo_db_guid
end
|
#touch ⇒ Object
164
165
166
|
# File 'lib/dyna_model/document.rb', line 164
def touch
self.send(:touch_timestamps, "updated_at")
end
|
#touch! ⇒ Object
168
169
170
171
|
# File 'lib/dyna_model/document.rb', line 168
def touch!
self.touch
self.save
end
|