Skip to content

Commit

Permalink
[rubygems/rubygems] Refactor bundle info
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez authored and hsbt committed Dec 13, 2023
1 parent 7042824 commit 1a7aa55
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
9 changes: 9 additions & 0 deletions lib/bundler/cli/common.rb
Expand Up @@ -57,6 +57,9 @@ def self.select_spec(name, regex_match = nil)
specs << spec if regexp && spec.name =~ 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 }
Expand All @@ -75,6 +78,12 @@ def self.select_spec(name, regex_match = nil)
raise GemNotFound, gem_not_found_message(name, Bundler.definition.dependencies)
end

def self.default_gem_spec(name)
return unless Gem::Specification.respond_to?(:find_all_by_name)
gem_spec = Gem::Specification.find_all_by_name(name).last
gem_spec if gem_spec&.default_gem?
end

def self.ask_for_spec_from(specs)
specs.each_with_index do |spec, index|
Bundler.ui.info "#{index.succ} : #{spec.name}", true
Expand Down
11 changes: 2 additions & 9 deletions lib/bundler/cli/info.rb
Expand Up @@ -25,15 +25,8 @@ def run

private

def spec_for_gem(gem_name)
spec = Bundler.definition.specs.find {|s| s.name == gem_name }
spec || default_gem_spec(gem_name) || Bundler::CLI::Common.select_spec(gem_name, :regex_match)
end

def default_gem_spec(gem_name)
return unless Gem::Specification.respond_to?(:find_all_by_name)
gem_spec = Gem::Specification.find_all_by_name(gem_name).last
gem_spec if gem_spec&.default_gem?
def spec_for_gem(name)
Bundler::CLI::Common.select_spec(name, :regex_match)
end

def print_gem_version(spec)
Expand Down

0 comments on commit 1a7aa55

Please sign in to comment.