class ActiveModel::EachValidator

Public Instance Methods

should_validate_field?(record, attribute) click to toggle source
# File lib/no_brainer/document/validation/core.rb, line 44
def should_validate_field?(record, attribute)
  return true unless record.is_a?(NoBrainer::Document)
  return true if record.new_record?

  attr_changed = "#{attribute}_changed?"
  return record.respond_to?(attr_changed) ? record.__send__(attr_changed) : true
end
validate(record) click to toggle source

XXX Monkey Patching :(

# File lib/no_brainer/document/validation/core.rb, line 53
def validate(record)
  attributes.each do |attribute|
    next unless should_validate_field?(record, attribute) # <--- Added
    value = record.read_attribute_for_validation(attribute)
    next if value.is_a?(NoBrainer::Document::AtomicOps::PendingAtomic) # <--- Added
    next if (value.nil? && options[:allow_nil]) || (value.blank? && options[:allow_blank])
    validate_each(record, attribute, value)
  end
end