Skip to content

Commit

Permalink
remove extra caching on spec
Browse files Browse the repository at this point in the history
The package object already caches the spec object, so we don't need to
do it multiple times.  Also introduce a consturctor for in-memory
installations so that we can rm the `spec` setter method
  • Loading branch information
tenderlove committed Apr 10, 2015
1 parent f606653 commit 620910a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
18 changes: 11 additions & 7 deletions lib/rubygems/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ class Gem::Installer

attr_reader :options

##
# Sets the specification for .gem-less installs.

attr_writer :spec

@path_warning = false

@install_lock = Mutex.new
Expand Down Expand Up @@ -108,6 +103,15 @@ def self.at path, options = {}
new package, options
end

##
# Construct an installer object for an ephemeral gem (one where we don't
# actually have a .gem file, just a spec)

def self.for_spec spec, options = {}
# FIXME: we should have a real Package class for this
new Struct.new(:spec).new(spec), options
end

##
# Constructs an Installer instance that will install the gem located at
# +gem+. +options+ is a Hash with the following keys:
Expand Down Expand Up @@ -225,7 +229,7 @@ def gem_dir
# Lazy accessor for the installer's spec.

def spec
@spec ||= @package.spec
@package.spec
rescue Gem::Package::Error => e
raise Gem::InstallError, "invalid gem: #{e.message}"
end
Expand All @@ -244,7 +248,7 @@ def spec
def install
pre_install_checks

FileUtils.rm_f File.join gem_home, 'specifications', @spec.spec_name
FileUtils.rm_f File.join gem_home, 'specifications', spec.spec_name

run_pre_install_hooks

Expand Down
3 changes: 1 addition & 2 deletions lib/rubygems/resolver/git_specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ def add_dependency dependency # :nodoc:
def install options = {}
require 'rubygems/installer'

installer = Gem::Installer.at '', options
installer.spec = spec
installer = Gem::Installer.for_spec spec, options

yield installer if block_given?

Expand Down
7 changes: 3 additions & 4 deletions test/rubygems/test_gem_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,8 @@ def test_generate_bin_symlink_update_older
util_make_exec
one = @spec.dup
one.version = 1
@installer = Gem::Installer.for_spec spec
@installer.gem_dir = util_gem_dir one
@installer.spec = spec

@installer.generate_bin

Expand Down Expand Up @@ -1427,7 +1427,6 @@ def test_write_cache_file
refute_path_exists cache_file

installer = Gem::Installer.at gem
installer.spec = @spec
installer.gem_home = @gemhome

installer.write_cache_file
Expand All @@ -1439,7 +1438,7 @@ def test_write_spec
FileUtils.rm @spec.spec_file
refute_path_exists @spec.spec_file

@installer.spec = @spec
@installer = Gem::Installer.for_spec @spec
@installer.gem_home = @gemhome

@installer.write_spec
Expand All @@ -1459,7 +1458,7 @@ def test_write_spec_writes_cached_spec

@spec.files = %w[a.rb b.rb c.rb]

@installer.spec = @spec
@installer = Gem::Installer.for_spec @spec
@installer.gem_home = @gemhome

@installer.write_spec
Expand Down

0 comments on commit 620910a

Please sign in to comment.