Factor out logic for finding gemspec
This commit is contained in:
parent
cb0cf76489
commit
0968c5ddce
|
@ -11,14 +11,8 @@ class Pry
|
|||
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)
|
||||
Dir.chdir(gem_spec(gem).full_gem_path)
|
||||
output.puts(Dir.pwd)
|
||||
else
|
||||
raise CommandError, "Gem `#{gem}` not found."
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,15 +12,9 @@ class Pry
|
|||
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) do
|
||||
Dir.chdir(gem_spec(gem).full_gem_path) do
|
||||
invoke_editor(".", 0, false)
|
||||
end
|
||||
else
|
||||
raise CommandError, "Gem `#{gem}` not found."
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -261,7 +261,21 @@ class Pry
|
|||
|
||||
Range.new(a, b)
|
||||
end
|
||||
|
||||
# Get the gem spec object for the given gem
|
||||
# @param [String] gem name
|
||||
# @return [Gem::Specification]
|
||||
def gem_spec(gem)
|
||||
specs = if Gem::Specification.respond_to?(:each)
|
||||
Gem::Specification.find_all_by_name(gem)
|
||||
else
|
||||
Gem.source_index.find_name(gem)
|
||||
end
|
||||
|
||||
spec = specs.sort_by{ |spec| Gem::Version.new(spec.version) }.first
|
||||
|
||||
spec or raise CommandError, "Gem `#{gem}` not found"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue