Sha256: 6d1e2dad9d6460995f039727375231cfba9cfa640964254472bc1753bf8ab4d5
Contents?: true
Size: 809 Bytes
Versions: 15
Compression:
Stored size: 809 Bytes
Contents
module Volt class LengthValidator def self.validate(model, field_name, args) errors = {} value = model.get(field_name) if args.is_a?(Fixnum) min = args max = nil message = nil elsif args.is_a?(Hash) min = args[:length] || args[:minimum] max = args[:maximum] fail 'length or minimum must be specified' unless min.is_a?(Fixnum) message = args[:message] else fail 'The arguments to length must be a number or a hash' end if !value || value.size < min errors[field_name] = [message || "must be at least #{min} characters"] elsif max && value.size > max errors[field_name] = [message || "must be less than #{max} characters"] end errors end end end
Version data entries
15 entries across 15 versions & 1 rubygems