module ArDocStore::Embedding::InstanceMethods

Public Instance Methods

embed_valid?(assn_name, record) click to toggle source

Returns whether or not the association is valid and applies any errors to the parent, self, if it wasn't. Skips any :autosave enabled records if they're marked_for_destruction? or destroyed.

# File lib/ar_doc_store/embedding.rb, line 26
def embed_valid?(assn_name, record)
  unless valid = record.valid?
    record.errors.each do |attribute, message|
      attribute = "#{assn_name}.#{attribute}"
      errors[attribute] << message
      errors[attribute].uniq!
    end
  end
  valid
end
validate_embeds_many(assn_name) click to toggle source
# File lib/ar_doc_store/embedding.rb, line 37
def validate_embeds_many(assn_name)
  if records = public_send(assn_name)
    records.each { |record| embed_valid?(assn_name, record) }
  end
end
validate_embeds_one(assn_name) click to toggle source
# File lib/ar_doc_store/embedding.rb, line 43
def validate_embeds_one(assn_name)
  record = public_send(assn_name)
  embed_valid?(assn_name, record) if record
end