module ArDocStore::EmbeddableModel::InstanceMethods

Public Class Methods

new(values={}) click to toggle source
Calls superclass method
# File lib/ar_doc_store/embeddable_model.rb, line 36
def initialize(values={})
  super(values)
  values && persisted? && values.keys.each do |key|
    mutations_from_database.forget_change(key)
  end
end

Public Instance Methods

as_json(_=nil) click to toggle source
# File lib/ar_doc_store/embeddable_model.rb, line 102
def as_json(_=nil)
  attributes.inject({}) do |attrs, attr|
    attrs[attr[0]] = attr[1] unless attr[1].nil?
    attrs
  end
end
embedded?() click to toggle source
# File lib/ar_doc_store/embeddable_model.rb, line 43
def embedded?
  true
end
ensure_id() click to toggle source
# File lib/ar_doc_store/embeddable_model.rb, line 51
def ensure_id
  self.id ||= SecureRandom.uuid
end
inspect() click to toggle source
# File lib/ar_doc_store/embeddable_model.rb, line 71
def inspect
  "#{self.class}: #{attributes.inspect}"
end
mark_embeds_as_persisted() click to toggle source
# File lib/ar_doc_store/embeddable_model.rb, line 55
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
new_record?() click to toggle source
# File lib/ar_doc_store/embeddable_model.rb, line 63
def new_record?
  id.blank?
end
persist() click to toggle source
# File lib/ar_doc_store/embeddable_model.rb, line 47
def persist
  run_callbacks :persist
end
persisted?() click to toggle source
# File lib/ar_doc_store/embeddable_model.rb, line 67
def persisted?
  id.present?
end
read_attribute(attribute) click to toggle source
# File lib/ar_doc_store/embeddable_model.rb, line 90
def read_attribute(attribute)
  attributes[attribute.to_s]
end
read_store_attribute(store, attr) click to toggle source
# File lib/ar_doc_store/embeddable_model.rb, line 75
def read_store_attribute(store, attr)
  attributes[attr.to_s]
end
to_param() click to toggle source
# File lib/ar_doc_store/embeddable_model.rb, line 98
def to_param
  id
end
write_attribute(attribute, value) click to toggle source
# File lib/ar_doc_store/embeddable_model.rb, line 94
def write_attribute(attribute, value)
  attributes[attribute.to_s] = value
end
write_store_attribute(store, attribute, value) click to toggle source
# File lib/ar_doc_store/embeddable_model.rb, line 79
def write_store_attribute(store, attribute, value)
  if parent
    if parent.is_a?(EmbeddedCollection)
      parent.save
    else
      parent.send :write_store_attribute, store, embedded_as, as_json
    end
  end
  value
end