Module: ArDocStore::Model::InstanceMethods

Defined in:
lib/ar_doc_store/model.rb

Instance Method Summary collapse

Instance Method Details

#assign_json_dataObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ar_doc_store/model.rb', line 12

def assign_json_data
  json_data = respond_to?(json_column) && self[json_column]
  return if json_data.blank?
  json_attributes.keys.each do |key|
    next unless json_data.key?(key)
    send :attribute=, key, json_data[key]
    self[key].parent = self if self[key].respond_to?(:parent)
    self[key].embedded_as = key if self[key].respond_to?(:embedded_as)
    mutations_from_database.forget_change(key) unless new_record?
  end
end

#mark_embeds_as_persistedObject



23
24
25
26
27
28
29
# File 'lib/ar_doc_store/model.rb', line 23

def mark_embeds_as_persisted
  json_attributes.values.each do |value|
    if value.respond_to?(:embedded?) && value.embedded? && respond_to?(value.attribute) && !public_send(value.attribute).nil?
      public_send(value.attribute).persist
    end
  end
end