Method: Bundler::CLI::Common.select_spec

Defined in:
lib/bundler/cli/common.rb

.select_spec(name, regex_match = nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/bundler/cli/common.rb', line 51

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.match?(regexp)
  end

  default_spec = default_gem_spec(name)
  specs << default_spec if default_spec

  case specs.count
  when 0
    dep_in_other_group = Bundler.definition.current_dependencies.find {|dep|dep.name == name }

    if dep_in_other_group
      raise GemNotFound, "Could not find gem '#{name}', because it's in the #{verbalize_groups(dep_in_other_group.groups)}, configured to be ignored."
    else
      raise GemNotFound, gem_not_found_message(name, Bundler.definition.dependencies)
    end
  when 1
    specs.first
  else
    ask_for_spec_from(specs)
  end
rescue RegexpError
  raise GemNotFound, gem_not_found_message(name, Bundler.definition.dependencies)
end