class Bundler::Source::Rubygems

def install(spec, options = {})

def install(spec, options = {})
  if (spec.default_gem? && !cached_built_in_gem(spec, local: options[:local])) || (installed?(spec) && !options[:force])
    print_using_message "Using #{version_message(spec, options[:previous_spec])}"
    return nil # no post-install message
  end
  if spec.remote
    # Check for this spec from other sources
    uris = [spec.remote, *remotes_for_spec(spec)].map(&:anonymized_uri).uniq
    Installer.ambiguous_gems << [spec.name, *uris] if uris.length > 1
  end
  path = fetch_gem_if_possible(spec, options[:previous_spec])
  raise GemNotFound, "Could not find #{spec.file_name} for installation" unless path
  return if Bundler.settings[:no_install]
  install_path = rubygems_dir
  bin_path     = Bundler.system_bindir
  require_relative "../rubygems_gem_installer"
  installer = Bundler::RubyGemsGemInstaller.at(
    path,
    security_policy: Bundler.rubygems.security_policies[Bundler.settings["trust-policy"]],
    install_dir: install_path.to_s,
    bin_dir: bin_path.to_s,
    ignore_dependencies: true,
    wrappers: true,
    env_shebang: true,
    build_args: options[:build_args],
    bundler_extension_cache_path: extension_cache_path(spec)
  )
  if spec.remote
    s = begin
      installer.spec
    rescue Gem::Package::FormatError
      Bundler.rm_rf(path)
      raise
    rescue Gem::Security::Exception => e
      raise SecurityError,
       "The gem #{File.basename(path, ".gem")} can't be installed because " \
       "the security policy didn't allow it, with the message: #{e.message}"
    end
    spec.__swap__(s)
  end
  spec.source.checksum_store.register(spec, installer.gem_checksum)
  message = "Installing #{version_message(spec, options[:previous_spec])}"
  message += " with native extensions" if spec.extensions.any?
  Bundler.ui.confirm message
  installed_spec = installer.install
  spec.full_gem_path = installed_spec.full_gem_path
  spec.loaded_from = installed_spec.loaded_from
  spec.base_dir = installed_spec.base_dir
  spec.post_install_message
end