Sha256: 5cb564441de8e3d559454ef60a48015e6b2463411255f2e1b92cd0efee270d77
Contents?: true
Size: 875 Bytes
Versions: 8
Compression:
Stored size: 875 Bytes
Contents
module Schemacop 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
Version data entries
8 entries across 8 versions & 1 rubygems