class Tuning::Validations::CountValidator

Constants

CHECKS
MESSAGES

Public Class Methods

new(options) click to toggle source
Calls superclass method
# File lib/tuning/validations/count.rb, line 9
def initialize(options)
  if range = (options[:in] || options[:within])
    options[:minimum] = range.min
    options[:maximum] = range.max
  end
  super
end

Public Instance Methods

validate_each(record, attribute, value) click to toggle source
# File lib/tuning/validations/count.rb, line 17
def validate_each(record, attribute, value)
  if value.respond_to?(:size)
    count = value.size
    CHECKS.each do |name, operator|
      if options.has_key?(name)
        other = options[name]
        unless count.send(operator, other)
          record.errors.add attribute, MESSAGES[name], count: other
        end
      end
    end
  else
    record.errors.add attribute, :uncountable
  end
end