Module: Sourcerer::Util::GemUri
- Defined in:
- lib/sourcerer/util/gem_uri.rb
Overview
Resolve gem:// URIs to absolute filesystem paths.
Not required internally; callers must require this file explicitly.
Constant Summary collapse
- GEM_URI_PATTERN =
%r{\Agem://([^/]+)/(.+)\z}
Class Method Summary collapse
-
.resolve(path) ⇒ String
Resolve a
gem://URI to an absolute path within the named gem's directory.
Class Method Details
.resolve(path) ⇒ String
Resolve a gem:// URI to an absolute path within the named gem's directory.
Returns path unchanged if it is not a gem:// URI.
URI format: gem://
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sourcerer/util/gem_uri.rb', line 21 def self.resolve path return path unless path.is_a?(String) && path.start_with?('gem://') match = GEM_URI_PATTERN.match(path) raise ArgumentError, "Invalid gem:// URI: #{path}" unless match spec = Gem.loaded_specs[match[1]] raise LoadError, "Gem '#{match[1]}' not loaded (referenced in gem:// URI: #{path})" unless spec File.join(spec.gem_dir, match[2]) end |