Method: Schemacop::V3::NumericNode#validate_self

Defined in:
lib/schemacop/v3/numeric_node.rb

#validate_selfObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/schemacop/v3/numeric_node.rb', line 63

def validate_self
  # Check that the options have the correct type
  ATTRIBUTES.each do |attribute|
    next if options[attribute].nil?
    next unless allowed_types.keys.none? { |c| options[attribute].send(type_assertion_method, c) }

    collection = allowed_types.values.map { |t| "\"#{t}\"" }.uniq.sort.join(' or ')
    fail "Option \"#{attribute}\" must be a #{collection}"
  end

  if options[:minimum] && options[:maximum] && options[:minimum] > options[:maximum]
    fail 'Option "minimum" can\'t be greater than "maximum".'
  end

  if options[:exclusive_minimum] && options[:exclusive_maximum]\
     && options[:exclusive_minimum] > options[:exclusive_maximum]
    fail 'Option "exclusive_minimum" can\'t be greater than "exclusive_maximum".'
  end

  if options[:multiple_of]&.zero?
    fail 'Option "multiple_of" can\'t be 0.'
  end
end