class Dinamo::Model::Validation::EachValidator

Attributes

attributes[R]

Public Class Methods

new(attributes: [], **options) click to toggle source
# File lib/dinamo/model/validator.rb, line 22
def initialize(attributes: [], **options)
  @attributes = attributes
  raise ArgumentError, ":attributes cannot be blank" if @attributes.empty?
  super
end

Public Instance Methods

validate(record) click to toggle source
# File lib/dinamo/model/validator.rb, line 28
def validate(record)
  attributes.each do |key, val|
    value = record[key]
    next if (value.nil? && options[:allow_nil]) ||
      (value.blank? && options[:allow_blank])
    validate_each(record, key, value)
  end
end
validate_each(record, attribute, value) click to toggle source
# File lib/dinamo/model/validator.rb, line 37
def validate_each(record, attribute, value)
  raise NotImplementedError
end