Sha256: 37bdd5dd083c6da83e17607925e0a613b3c43720ecc63261006e6701453612ca

Contents?: true

Size: 605 Bytes

Versions: 5

Compression:

Stored size: 605 Bytes

Contents

module Schemacop
  class ObjectValidator < Node
    register symbols: :object, klasses: Object

    option :classes
    option :strict

    def type_label
      "#{super} (#{classes.join(', ')})"
    end

    def type_matches?(data)
      if option(:strict).is_a?(FalseClass)
        sub_or_class = classes.map { |klass| data.class <= klass }.include?(true)
        super && (classes.empty? || sub_or_class) && !data.nil?
      else
        super && (classes.empty? || classes.include?(data.class)) && !data.nil?
      end
    end

    private

    def classes
      [*option(:classes)]
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
schemacop-2.4.1 lib/schemacop/validator/object_validator.rb
schemacop-2.4.0 lib/schemacop/validator/object_validator.rb
schemacop-2.3.2 lib/schemacop/validator/object_validator.rb
schemacop-2.3.1 lib/schemacop/validator/object_validator.rb
schemacop-2.3.0 lib/schemacop/validator/object_validator.rb