Class: Hocon::Impl::Url
- Inherits:
-
Object
- Object
- Hocon::Impl::Url
- Defined in:
- lib/hocon/impl/url.rb
Overview
There are several places in the Java codebase that use Java’s URL constructor, and rely on it to throw a ‘MalformedURLException` if the URL isn’t valid.
Ruby doesn’t really have a similar constructor / validator, so this is a little shim to hopefully make the ported code match up with the upstream more closely.
Defined Under Namespace
Classes: MalformedUrlError
Instance Method Summary collapse
-
#initialize(url) ⇒ Url
constructor
A new instance of Url.
- #to_s ⇒ Object
Constructor Details
#initialize(url) ⇒ Url
Returns a new instance of Url.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/hocon/impl/url.rb', line 22 def initialize(url) begin # URI::parse wants a string @url = URI.parse(url.to_s) if !(@url.kind_of?(URI::HTTP)) raise MalformedUrlError, "Unrecognized URL: '#{url}'" end rescue URI::InvalidURIError => e raise MalformedUrlError.new("Unrecognized URL: '#{url}' (error: #{e})", e) end end |
Instance Method Details
#to_s ⇒ Object
34 35 36 |
# File 'lib/hocon/impl/url.rb', line 34 def to_s @url.to_s end |