Sha256: 1f37b333409bfb21a1f79c2adab59f655fdcde92740f45b2c6950cf06229d726
Contents?: true
Size: 871 Bytes
Versions: 9
Compression:
Stored size: 871 Bytes
Contents
module OptParseValidator # Implementation of the URI Option class OptURI < OptBase def allowed_protocols @allowed_protocols ||= [*attrs[:protocols]] end # The default protocol (or scheme) to use if none was given def default_protocol @default_protocol ||= attrs[:default_protocol] end # @param [ String ] value # # @return [ String ] def validate(value) uri = Addressable::URI.parse(value) if !uri.scheme && default_protocol uri = Addressable::URI.parse("#{default_protocol}://#{value}") end unless allowed_protocols.empty? || allowed_protocols.include?(uri.scheme) # For future refs: will have to check if the uri.scheme exists, # otherwise it means that the value was empty fail Addressable::URI::InvalidURIError end uri.to_s end end end
Version data entries
9 entries across 9 versions & 1 rubygems