class Chef::Provider::Package::Rubygems::AlternateGemEnvironment

Constants

JRUBY_PLATFORM

Attributes

gem_binary_location[R]

Public Class Methods

gempath_cache() click to toggle source
# File lib/chef/provider/package/rubygems.rb, line 287
def self.gempath_cache
  @gempath_cache ||= {}
end
new(gem_binary_location) click to toggle source
# File lib/chef/provider/package/rubygems.rb, line 299
def initialize(gem_binary_location)
  @gem_binary_location = gem_binary_location
end
platform_cache() click to toggle source
# File lib/chef/provider/package/rubygems.rb, line 291
def self.platform_cache
  @platform_cache ||= {}
end

Public Instance Methods

candidate_version_from_remote(gem_dependency, *sources) click to toggle source
# File lib/chef/provider/package/rubygems.rb, line 368
def candidate_version_from_remote(gem_dependency, *sources)
  with_gem_sources(*sources) do
    with_gem_platforms(*gem_platforms) do
      find_newest_remote_version(gem_dependency, *sources)
    end
  end
end
gem_paths() click to toggle source
# File lib/chef/provider/package/rubygems.rb, line 307
def gem_paths
  if self.class.gempath_cache.key?(@gem_binary_location)
    self.class.gempath_cache[@gem_binary_location]
  else
    # shellout! is a fork/exec which won't work on windows
    shell_style_paths = shell_out!("#{@gem_binary_location} env gempath").stdout
    # on windows, the path separator is (usually? always?) semicolon
    paths = shell_style_paths.split(::File::PATH_SEPARATOR).map(&:strip)
    self.class.gempath_cache[@gem_binary_location] = paths
  end
end
gem_platforms() click to toggle source

Attempt to detect the correct platform settings for the target gem environment.

In practice, this only makes a difference if different versions are available depending on platform, and only if the target gem environment has a radically different platform (i.e., jruby), so we just try to detect jruby and fall back to the current platforms (Gem.platforms) if we don't detect it.

Returns

String|Gem::Platform

returns an array of Gem::Platform-compatible

objects, i.e., Strings that are valid for Gem::Platform or actual Gem::Platform objects.

# File lib/chef/provider/package/rubygems.rb, line 346
def gem_platforms
  if self.class.platform_cache.key?(@gem_binary_location)
    self.class.platform_cache[@gem_binary_location]
  else
    gem_environment = shell_out!("#{@gem_binary_location} env").stdout
    self.class.platform_cache[@gem_binary_location] = if jruby = gem_environment[JRUBY_PLATFORM]
                                                        ["ruby", Gem::Platform.new(jruby)]
                                                      else
                                                        Gem.platforms
                                                      end
  end
end
gem_source_index() click to toggle source
# File lib/chef/provider/package/rubygems.rb, line 319
def gem_source_index
  @source_index ||= Gem::SourceIndex.from_gems_in(*gem_paths.map { |p| p + "/specifications" })
end
gem_specification() click to toggle source
# File lib/chef/provider/package/rubygems.rb, line 323
def gem_specification
  # Only once, dirs calls a reset
  unless @specification
    Gem::Specification.dirs = gem_paths
    @specification = Gem::Specification
  end
  @specification
end
rubygems_version() click to toggle source
# File lib/chef/provider/package/rubygems.rb, line 303
def rubygems_version
  @rubygems_version ||= shell_out!("#{@gem_binary_location} --version").stdout.chomp
end
with_gem_platforms(*alt_gem_platforms) { || ... } click to toggle source
# File lib/chef/provider/package/rubygems.rb, line 359
def with_gem_platforms(*alt_gem_platforms)
  alt_gem_platforms.flatten!
  original_gem_platforms = Gem.platforms
  Gem.platforms = alt_gem_platforms
  yield
ensure
  Gem.platforms = original_gem_platforms
end