module Puppet::Pops::Loader::GemSupport
GemSupport
offers methods to find a gem's location by name or gem://gemname URI.
TODO: The Puppet
3x, uses Puppet::Util::RubyGems
to do this, and obtain paths, and avoids using ::Gems when ::Bundler is in effect. A quick check what happens on Ruby 1.8.7 and Ruby 1.9.3 with current version of bundler seems to work just fine without jumping through any hoops. Hopefully the Puppet::Utils::RubyGems is just dealing with arcane things prior to RubyGems 1.8 that are not needed any more. To verify there is the need to set up a scenario where additional bundles than what Bundler allows for a given configuration are available and then trying to access those.
Public Instance Methods
Produces the root directory of a gem given as an URI (gem://gemname/optional/path), or just the gemname as a string.
# File lib/puppet/pops/loader/gem_support.rb 15 def gem_dir(uri_or_string) 16 case uri_or_string 17 when URI 18 gem_dir_from_uri(uri_or_string) 19 when String 20 gem_dir_from_name(uri_or_string) 21 end 22 end
Produces the root directory of a gem given as a string with the gem's name. TODO: FIND by name raises exception Gem::LoadError with list of all gems on the path
# File lib/puppet/pops/loader/gem_support.rb 44 def gem_dir_from_name(gem_name) 45 spec = Gem::Specification.find_by_name(gem_name) 46 unless spec 47 raise ArgumentError, _("Gem not found '%{gem_name}'") % { gem_name: gem_name } 48 end 49 spec.full_gem_path 50 end
Produces the root directory of a gem given as an uri, where hostname is the gemname, and an optional path is appended to the root of the gem (i.e. if the reference is given to a sub-location within a gem. TODO: FIND by name raises exception Gem::LoadError with list of all gems on the path
# File lib/puppet/pops/loader/gem_support.rb 28 def gem_dir_from_uri(uri) 29 spec = Gem::Specification.find_by_name(uri.hostname) 30 unless spec 31 raise ArgumentError, _("Gem not found %{uri}") % { uri: uri } 32 end 33 # if path given append that, else append given subdir 34 if uri.path.empty? 35 spec.gem_dir 36 else 37 File.join(spec.full_gem_path, uri.path) 38 end 39 end