Class: ActiveModel::EachValidator
- Inherits:
-
Object
- Object
- ActiveModel::EachValidator
- Defined in:
- lib/no_brainer/document/validation/core.rb
Direct Known Subclasses
NoBrainer::Document::Validation::NotNull::NotNullValidator, NoBrainer::Document::Validation::Uniqueness::UniquenessValidator
Instance Method Summary collapse
- #should_validate_field?(record, attribute) ⇒ Boolean
-
#validate(record) ⇒ Object
XXX Monkey Patching :(.
Instance Method Details
#should_validate_field?(record, attribute) ⇒ Boolean
44 45 46 47 48 49 50 |
# 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) ⇒ Object
XXX Monkey Patching :(
53 54 55 56 57 58 59 60 61 |
# 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? && [:allow_nil]) || (value.blank? && [:allow_blank]) validate_each(record, attribute, value) end end |