diff options
Diffstat (limited to 'lib/rubygems/commands/unpack_command.rb')
-rw-r--r-- | lib/rubygems/commands/unpack_command.rb | 53 |
1 files changed, 23 insertions, 30 deletions
diff --git a/lib/rubygems/commands/unpack_command.rb b/lib/rubygems/commands/unpack_command.rb index 3f1708375f..c2fc720297 100644 --- a/lib/rubygems/commands/unpack_command.rb +++ b/lib/rubygems/commands/unpack_command.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true -require_relative '../command' -require_relative '../version_option' -require_relative '../security_option' -require_relative '../remote_fetcher' -require_relative '../package' + +require_relative "../command" +require_relative "../version_option" +require_relative "../security_option" +require_relative "../remote_fetcher" +require_relative "../package" # forward-declare @@ -17,18 +18,18 @@ class Gem::Commands::UnpackCommand < Gem::Command include Gem::SecurityOption def initialize - require 'fileutils' + require "fileutils" - super 'unpack', 'Unpack an installed gem to the current directory', - :version => Gem::Requirement.default, - :target => Dir.pwd + super "unpack", "Unpack an installed gem to the current directory", + version: Gem::Requirement.default, + target: Dir.pwd - add_option('--target=DIR', - 'target directory for unpacking') do |value, options| + add_option("--target=DIR", + "target directory for unpacking") do |value, options| options[:target] = value end - add_option('--spec', 'unpack the gem specification') do |value, options| + add_option("--spec", "unpack the gem specification") do |_value, options| options[:spec] = true end @@ -95,19 +96,17 @@ command help for an example. FileUtils.mkdir_p @options[:target] if @options[:target] - destination = begin - if @options[:target] - File.join @options[:target], spec_file - else - spec_file - end + destination = if @options[:target] + File.join @options[:target], spec_file + else + spec_file end - File.open destination, 'w' do |io| + File.open destination, "w" do |io| io.write metadata end else - basename = File.basename path, '.gem' + basename = File.basename path, ".gem" target_dir = File.expand_path basename, options[:target] package = Gem::Package.new path, security_policy @@ -131,7 +130,7 @@ command help for an example. return this_path if File.exist? this_path end - return nil + nil end ## @@ -144,24 +143,18 @@ command help for an example. # get_path 'rake', '< 0.1' # nil # get_path 'rak' # nil (exact name required) #-- - # TODO: This should be refactored so that it's a general service. I don't - # think any of our existing classes are the right place though. Just maybe - # 'Cache'? - # - # TODO: It just uses Gem.dir for now. What's an easy way to get the list of - # source directories? def get_path(dependency) - return dependency.name if dependency.name =~ /\.gem$/i + return dependency.name if /\.gem$/i.match?(dependency.name) specs = dependency.matching_specs - selected = specs.max_by {|s| s.version } + selected = specs.max_by(&:version) return Gem::RemoteFetcher.fetcher.download_to_cache(dependency) unless selected - return unless dependency.name =~ /^#{selected.name}$/i + return unless /^#{selected.name}$/i.match?(dependency.name) # We expect to find (basename).gem in the 'cache' directory. Furthermore, # the name match must be exact (ignoring case). |