Module: ArDocStore::Embedding::InstanceMethods

Defined in:
lib/ar_doc_store/embedding.rb

Instance Method Summary collapse

Instance Method Details

#embed_valid?(assn_name, record) ⇒ Boolean

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.

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
33
# File 'lib/ar_doc_store/embedding.rb', line 24

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) ⇒ Object



35
36
37
38
39
# File 'lib/ar_doc_store/embedding.rb', line 35

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) ⇒ Object



41
42
43
44
# File 'lib/ar_doc_store/embedding.rb', line 41

def validate_embeds_one(assn_name)
  record = public_send(assn_name)
  embed_valid?(assn_name, record) if record
end