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

Version Path
schemacop-3.0.29 lib/schemacop/v2/validator/array_validator.rb
schemacop-3.0.28 lib/schemacop/v2/validator/array_validator.rb
schemacop-3.0.27 lib/schemacop/v2/validator/array_validator.rb
schemacop-3.0.26 lib/schemacop/v2/validator/array_validator.rb
schemacop-3.0.25 lib/schemacop/v2/validator/array_validator.rb
schemacop-3.0.24 lib/schemacop/v2/validator/array_validator.rb
schemacop-3.0.23 lib/schemacop/v2/validator/array_validator.rb
schemacop-3.0.22 lib/schemacop/v2/validator/array_validator.rb
schemacop-3.0.21 lib/schemacop/v2/validator/array_validator.rb
schemacop-3.0.20 lib/schemacop/v2/validator/array_validator.rb
schemacop-3.0.19 lib/schemacop/v2/validator/array_validator.rb
schemacop-3.0.18 lib/schemacop/v2/validator/array_validator.rb
schemacop-3.0.17 lib/schemacop/v2/validator/array_validator.rb
schemacop-3.0.16 lib/schemacop/v2/validator/array_validator.rb
schemacop-3.0.15 lib/schemacop/v2/validator/array_validator.rb
schemacop-3.0.14 lib/schemacop/v2/validator/array_validator.rb
schemacop-3.0.13 lib/schemacop/v2/validator/array_validator.rb
schemacop-3.0.12 lib/schemacop/v2/validator/array_validator.rb
schemacop-3.0.11 lib/schemacop/v2/validator/array_validator.rb
schemacop-3.0.10 lib/schemacop/v2/validator/array_validator.rb