aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bundler/cli/common.rb
diff options
context:
space:
mode:
authorSmit Shah <who828@gmail.com>2014-01-08 09:02:52 +0530
committerSmit Shah <who828@gmail.com>2014-01-08 11:00:31 +0530
commitb51005d343b50c1cc151601a033647ab722c7e17 (patch)
tree7a4938ceb79d76e32081b43d68d567b1e8d0103e /lib/bundler/cli/common.rb
parente446339356d3fc951fbbd5ea614fb6bf4fb3e2fe (diff)
downloadbundler-b51005d343b50c1cc151601a033647ab722c7e17.tar.gz
Refactored open and fixed few failing specs
Diffstat (limited to 'lib/bundler/cli/common.rb')
-rw-r--r--lib/bundler/cli/common.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/bundler/cli/common.rb b/lib/bundler/cli/common.rb
index c1a9645f..e7e3f250 100644
--- a/lib/bundler/cli/common.rb
+++ b/lib/bundler/cli/common.rb
@@ -7,5 +7,41 @@ module Bundler
group_str = (groups.size == 1) ? "group" : "groups"
"Gems in the #{group_str} #{group_list} were not installed."
end
+
+ def self.select_spec(name, regex_match = nil)
+ specs = []
+ regexp = Regexp.new(name) if regex_match
+
+ Bundler.definition.specs.each do |spec|
+ return spec if spec.name == name
+ specs << spec if regexp && spec.name =~ regexp
+ end
+
+ case specs.count
+ when 0
+ raise GemNotFound, not_found_message(name, Bundler.definition.dependencies)
+ when 1
+ specs.first
+ else
+ specs.each_with_index do |spec, index|
+ Bundler.ui.info "#{index.succ} : #{spec.name}", true
+ end
+ Bundler.ui.info '0 : - exit -', true
+
+ input = Bundler.ui.ask('> ')
+ (num = input.to_i) > 0 ? specs[num - 1] : nil
+ end
+ end
+
+ def self.not_found_message(missing_gem_name, alternatives)
+ message = "Could not find gem '#{missing_gem_name}'."
+
+ # This is called as the result of a GemNotFound, let's see if
+ # there's any similarly named ones we can propose instead
+ alternate_names = alternatives.map { |a| a.respond_to?(:name) ? a.name : a }
+ suggestions = SimilarityDetector.new(alternate_names).similar_word_list(missing_gem_name)
+ message += "\nDid you mean #{suggestions}?" if suggestions
+ message
+ end
end
end