Class: Schemacop::V2::ObjectValidator

Inherits:
Node
  • Object
show all
Defined in:
lib/schemacop/v2/validator/object_validator.rb

Instance Attribute Summary

Attributes inherited from Node

#options

Instance Method Summary collapse

Methods inherited from Node

build, class_matches?, clear_klasses, clear_symbols, #exec_block, #initialize, klass, #option, option, #option?, register, #resolve_type_klass, symbol, symbol_matches?, #type_filter_matches?, type_matches?, #validate

Constructor Details

This class inherits a constructor from Schemacop::V2::Node

Instance Method Details

#type_labelObject



9
10
11
# File 'lib/schemacop/v2/validator/object_validator.rb', line 9

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

#type_matches?(data) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
# File 'lib/schemacop/v2/validator/object_validator.rb', line 13

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