Sha256: 50699b7d3781720c8357071cdf038c0f1dc2433d20357355a94d8c203635705c
Contents?: true
Size: 941 Bytes
Versions: 36
Compression:
Stored size: 941 Bytes
Contents
module Schemacop module V2 class ArrayValidator < NodeSupportingType register symbols: :array, klasses: Array option :min # Minimal number of elements option :max # Maximal number of elements option :nil # Whether to allow nil values def initialize(*args) super type(:nil) if option(:nil) end def validate(data, collector) validate_custom_check(data, collector) if option?(:min) && data.size < option(:min) collector.error "Array must have more (>=) than #{option(:min)} elements." end if option?(:max) && data.size > option(:max) collector.error "Array must have less (<=) than #{option(:max)} elements." end data.each_with_index do |entry, index| collector.path("[#{index}]", index, :array) do validate_types(entry, collector) end end end end end end
Version data entries
36 entries across 36 versions & 1 rubygems