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

Returns:

  • (Boolean)


66
67
68
# File 'lib/dyna_model/document.rb', line 66

def all_attributes_loaded?
  self.instance_variable_get("@_select") == :all
end

#dynamo_db_guidObject



54
55
56
57
58
# File 'lib/dyna_model/document.rb', line 54

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_valuesObject



60
61
62
63
64
# File 'lib/dyna_model/document.rb', line 60

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

#load_attributes!Object

When only partial attributes were selected (via GSI or projected attributes on an index)



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/dyna_model/document.rb', line 71

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_paramObject



50
51
52
# File 'lib/dyna_model/document.rb', line 50

def to_param
  self.dynamo_db_guid
end

#touchObject



86
87
88
# File 'lib/dyna_model/document.rb', line 86

def touch
  self.send(:touch_timestamps, "updated_at")
end

#touch!Object



90
91
92
93
# File 'lib/dyna_model/document.rb', line 90

def touch!
  self.touch
  self.save
end