Class: SBOM::CycloneDX::Validator::URIValidator
- Inherits:
-
BaseValidator
- Object
- BaseValidator
- SBOM::CycloneDX::Validator::URIValidator
- Defined in:
- lib/sbom/cyclone_dx/validator/uri_validator.rb
Constant Summary
Constants inherited from BaseValidator
BaseValidator::INVALID_TYPE, BaseValidator::MISSING_REQUIRED
Instance Method Summary collapse
-
#initialize(required: false) ⇒ URIValidator
constructor
A new instance of URIValidator.
- #validate(value) ⇒ Object
Methods inherited from BaseValidator
#raw_types, #required?, #valid?
Constructor Details
#initialize(required: false) ⇒ URIValidator
Returns a new instance of URIValidator.
11 12 13 |
# File 'lib/sbom/cyclone_dx/validator/uri_validator.rb', line 11 def initialize(required: false) super(::URI::Generic, String, required: required) end |
Instance Method Details
#validate(value) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/sbom/cyclone_dx/validator/uri_validator.rb', line 15 def validate(value) rv = super return rv unless value.is_a?(::URI::Generic) || value.is_a?(String) begin # Steep is, for some reason, looking at OpenURI's ::URI, and not ::URI from stdlib... uri_value = value.is_a?(URI::Generic) ? value : URI.parse(value) return rv if uri_value.scheme.present? rescue NoMethodError, URI::Error # Do nothing, all errors handled below end rv << "Invalid URI" end |