Class: JSON::Schema::IPFormat
- Inherits:
-
FormatAttribute
- Object
- Attribute
- FormatAttribute
- JSON::Schema::IPFormat
- Defined in:
- lib/json-schema/attributes/formats/ip.rb
Constant Summary
Constants inherited from Attribute
Attribute::TYPE_CLASS_MAPPINGS
Class Method Summary collapse
- .ip_version ⇒ Object
- .validate(current_schema, data, fragments, processor, validator, options = {}) ⇒ Object
Methods inherited from Attribute
build_fragment, data_valid_for_type?, type_of_data, validation_error, validation_errors
Class Method Details
.ip_version ⇒ Object
24 25 26 |
# File 'lib/json-schema/attributes/formats/ip.rb', line 24 def self.ip_version raise NotImplementedError end |
.validate(current_schema, data, fragments, processor, validator, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/json-schema/attributes/formats/ip.rb', line 8 def self.validate(current_schema, data, fragments, processor, validator, = {}) return unless data.is_a?(String) begin ip = IPAddr.new(data) rescue ArgumentError => e raise e unless e. == 'invalid address' end family = ip_version == 6 ? Socket::AF_INET6 : Socket::AF_INET unless ip && ip.family == family = "The property '#{build_fragment(fragments)}' must be a valid IPv#{ip_version} address" validation_error(processor, , fragments, current_schema, self, [:record_errors]) end end |