Skip to content

Commit de3f8d0

Browse files
committed
add an installer constructor for paths
This allows us to provide objects that quack like a `Gem::Package` to the installer class via `new`.
1 parent de3d2d3 commit de3f8d0

15 files changed

+55
-40
lines changed

lib/rubygems/commands/install_command.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def install_gem_without_dependencies name, req # :nodoc:
275275
gem = fetcher.download_to_cache dependency
276276
end
277277

278-
inst = Gem::Installer.new gem, options
278+
inst = Gem::Installer.at gem, options
279279
inst.install
280280

281281
require 'rubygems/dependency_installer'

lib/rubygems/commands/pristine_command.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def execute
156156
install_defaults.to_s['--env-shebang']
157157
end
158158

159-
installer = Gem::Installer.new(gem,
159+
installer = Gem::Installer.at(gem,
160160
:wrappers => true,
161161
:force => true,
162162
:install_dir => spec.base_dir,

lib/rubygems/installer.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ def exec_format
9999

100100
end
101101

102+
##
103+
# Construct an installer object for the gem file located at +path+
104+
105+
def self.at path, options = {}
106+
package = Gem::Package.new path
107+
new package, options
108+
end
109+
102110
##
103111
# Constructs an Installer instance that will install the gem located at
104112
# +gem+. +options+ is a Hash with the following keys:
@@ -122,11 +130,18 @@ def exec_format
122130
# :build_args:: An Array of arguments to pass to the extension builder
123131
# process. If not set, then Gem::Command.build_args is used
124132

125-
def initialize(gem, options={})
133+
def initialize(package, options={})
126134
require 'fileutils'
127135

128136
@options = options
129-
@package = Gem::Package.new gem
137+
if package.is_a? String
138+
@package = Gem::Package.new package
139+
if $VERBOSE
140+
warn "constructing an Installer object with a string is deprecated. Please use Gem::Installer.at (called from: #{caller.first})"
141+
end
142+
else
143+
@package = package
144+
end
130145

131146
process_options
132147

lib/rubygems/installer_test_case.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,15 @@ def util_setup_gem(ui = @ui) # HACK fix use_ui to make this automatic
176176
end
177177
end
178178

179-
@installer = Gem::Installer.new @gem
179+
@installer = Gem::Installer.at @gem
180180
end
181181

182182
##
183183
# Creates an installer for +spec+ that will install into +gem_home+. If
184184
# +user+ is true a user-install will be performed.
185185

186186
def util_installer(spec, gem_home, user=false)
187-
Gem::Installer.new(spec.cache_file,
187+
Gem::Installer.at(spec.cache_file,
188188
:install_dir => gem_home,
189189
:user_install => user)
190190
end

lib/rubygems/request_set.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def install options, &block # :yields: request, installer
159159

160160
path = req.download cache_dir
161161

162-
inst = Gem::Installer.new path, options
162+
inst = Gem::Installer.at path, options
163163

164164
yield req, inst if block_given?
165165

lib/rubygems/resolver/git_specification.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def add_dependency dependency # :nodoc:
2323
def install options = {}
2424
require 'rubygems/installer'
2525

26-
installer = Gem::Installer.new '', options
26+
installer = Gem::Installer.at '', options
2727
installer.spec = spec
2828

2929
yield installer if block_given?

lib/rubygems/resolver/specification.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def install options = {}
8989

9090
gem = source.download spec, destination
9191

92-
installer = Gem::Installer.new gem, options
92+
installer = Gem::Installer.at gem, options
9393

9494
yield installer if block_given?
9595

lib/rubygems/test_case.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ def install_gem spec, options = {}
488488
gem = File.join(@tempdir, File.basename(spec.cache_file)).untaint
489489
end
490490

491-
Gem::Installer.new(gem, options.merge({:wrappers => true})).install
491+
Gem::Installer.at(gem, options.merge({:wrappers => true})).install
492492
end
493493

494494
##

test/rubygems/simple_gem.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
@directory = options[:directory] || Gem.dir
1717
@force = options[:force]
1818
19-
gem = Gem::Installer.new(__FILE__).install(@force, @directory)
19+
gem = Gem::Installer.at(__FILE__).install(@force, @directory)
2020
if options[:gen_rdoc]
2121
Gem::DocManager.new(gem).generate_rdoc
2222
end

test/rubygems/test_gem_commands_install_command.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ def test_execute_uses_deps_a_gemdeps_with_a_path
910910
fetcher.gem 'r', '2.0', 'q' => nil
911911
end
912912

913-
i = Gem::Installer.new specs['q-1.0'].cache_file, :install_dir => "gf-path"
913+
i = Gem::Installer.at specs['q-1.0'].cache_file, :install_dir => "gf-path"
914914
i.install
915915

916916
assert File.file?("gf-path/specifications/q-1.0.gemspec"), "not installed"

0 commit comments

Comments
 (0)