1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00
pry--pry/lib/pry/commands/gem_cd.rb
2012-08-11 17:39:25 -07:00

20 lines
721 B
Ruby

class Pry
Pry::Commands.create_command "gem-cd", "Change working directory to specified gem's directory.", :argument_required => true do |gem|
banner <<-BANNER
Usage: gem-cd GEM_NAME
Change the current working directory to that in which the given gem is installed.
BANNER
def process(gem)
specs = Gem::Specification.respond_to?(:each) ? Gem::Specification.find_all_by_name(gem) : Gem.source_index.find_name(gem)
spec = specs.sort { |a,b| Gem::Version.new(b.version) <=> Gem::Version.new(a.version) }.first
if spec
Dir.chdir(spec.full_gem_path)
output.puts(Dir.pwd)
else
raise CommandError, "Gem `#{gem}` not found."
end
end
end
end