Class: OpenC3::RubygemsUrl
- Defined in:
- lib/openc3/utilities/rubygems_url.rb
Constant Summary collapse
- DEFAULT =
'https://rubygems.org'
Class Method Summary collapse
-
.validate(rubygems_url) ⇒ String
Validate that a resolved rubygems_url is an http(s) URL before it is used as a Gem source.
Class Method Details
.validate(rubygems_url) ⇒ String
Validate that a resolved rubygems_url is an http(s) URL before it is used as a Gem source. The value can come from a user-writable setting or ENV, so a malformed or non-http value is rejected and replaced with the default rather than passed through to RubyGems.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/openc3/utilities/rubygems_url.rb', line 28 def self.validate(rubygems_url) uri = URI.parse(rubygems_url) unless uri.is_a?(URI::HTTP) && !uri.host.to_s.empty? raise URI::InvalidURIError, "not an http(s) URL" end rubygems_url rescue URI::InvalidURIError => e Logger.error("Invalid rubygems_url '#{rubygems_url}' (#{e.}); falling back to #{DEFAULT}") DEFAULT end |