1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Refactored Pry::Helpers::BaseHelpers#gem_installed? to use Gem::Specification.find_all_by_name rather than the deprecated Gem.source_index

Refactored gem-list to use Gem::Specification.each rather than the deprecated Gem.source_index
Changed gem-cd to use Gem::Specification.each rather than the deprecated Gem.source_index
This commit is contained in:
David Palm 2011-05-31 13:33:19 +02:00
parent 2100bf4f83
commit 502a8764fe
2 changed files with 6 additions and 6 deletions

View file

@ -238,8 +238,8 @@ e.g: gist -d my_method
command "gem-cd", "Change working directory to specified gem's directory." do |gem_name|
require 'rubygems'
gem_spec = Gem.source_index.find_name(gem_name).first
next output.puts("Gem `#{gem_name}` not found.") if !gem_spec
gem_spec = Gem::Specification.find_all_by_name(gem_name).first # find_by_name raises Gem::LoadError which is irksome
next output.puts("Gem `#{gem_name}` not found.") unless gem_spec
Dir.chdir(File.expand_path(gem_spec.full_gem_path))
end
@ -330,13 +330,13 @@ e.g: gist -d my_method
command "gem-list", "List/search installed gems. (Optional parameter: a regexp to limit the search)" do |arg|
gems = Gem.source_index.gems.values.group_by(&:name)
if arg
query = Regexp.new(arg, Regexp::IGNORECASE)
gems = gems.select { |gemname, specs| gemname =~ query }
else
query = //
end
gems.each do |gemname, specs|
Gem::Specification.select{|spec| spec.name =~ query }.group_by(&:name).each do |gemname, specs|
versions = specs.map(&:version).sort.reverse.map(&:to_s)
versions = ["<bright_green>#{versions.first}</bright_green>"] +
versions[1..-1].map{|v| "<green>#{v}</green>" }

View file

@ -6,7 +6,7 @@ class Pry
def gem_installed?(gem_name)
require 'rubygems'
!!Gem.source_index.find_name(gem_name).first
!Gem::Specification.find_all_by_name(gem_name).empty?
end
def command_dependencies_met?(options)