Module: Puppet::Pops::Loader::UriHelper

Defined in:
lib/puppet/pops/loader/uri_helper.rb

Instance Method Summary collapse

Instance Method Details

#path_for_uri(uri, subdir = 'lib') ⇒ Object

Raises an exception if specified gem can not be located



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/puppet/pops/loader/uri_helper.rb', line 4

def path_for_uri(uri, subdir='lib')
  case uri.scheme
  when "gem"
    begin
      spec = Gem::Specification.find_by_name(uri.hostname)
      # if path given append that, else append given subdir
      File.join(spec.gem_dir, uri.path.empty?() ? subdir : uri.path)
    rescue StandardError => e
      raise "TODO TYPE: Failed to located gem #{uri}. #{e.message}"
    end
  when "file"
    File.join(uri.path, subdir)
  when nil
    File.join(uri.path, subdir)
  else
    raise "Not a valid scheme for a loader: #{uri.scheme}. Use a 'file:' (or just a path), or 'gem://gemname[/path]"
  end
end