diff options
author | Colby Swandale <colby@taplaboratories.com> | 2017-02-19 12:44:49 +1100 |
---|---|---|
committer | Colby Swandale <colby@taplaboratories.com> | 2017-02-19 12:44:49 +1100 |
commit | b1b9557046a8eccaf16e842e6eb53aba7be48ab4 (patch) | |
tree | a4ac5487dae511ccd2e8ef918f559a92f4b9224e /lib/bundler/cli/info.rb | |
parent | 1f5e97cdfeee1ca1578b2b42dca41bfa10363be6 (diff) | |
download | bundler-b1b9557046a8eccaf16e842e6eb53aba7be48ab4.tar.gz |
cleanup and add output for default gem
Diffstat (limited to 'lib/bundler/cli/info.rb')
-rw-r--r-- | lib/bundler/cli/info.rb | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/lib/bundler/cli/info.rb b/lib/bundler/cli/info.rb index 20a682fe48..250a16abb2 100644 --- a/lib/bundler/cli/info.rb +++ b/lib/bundler/cli/info.rb @@ -10,21 +10,30 @@ module Bundler end def run - begin - gem = Gem::Specification.find_by_name(gem_name) - spec = gem if gem.default_gem? - rescue Gem::MissingSpecError - nil - end - - spec ||= Bundler::CLI::Common.select_spec(gem_name, :regex_match) - return unless spec + spec = spec_for_gem(gem_name) + + spec_not_found(gem_name) unless spec return print_gem_path(spec) if @options[:path] print_gem_info(spec) end private + def spec_for_gem(gem_name) + spec = Bundler.definition.specs.find { |s| s.name == gem_name } + spec ||= default_gem_spec(gem_name) + end + + def default_gem_spec(gem_name) + return nil unless Gem::Specification.respond_to?(:find_all_by_name) + gem_spec = Gem::Specification.find_all_by_name(gem_name).last + return gem_spec if gem_spec && gem_spec.default_gem? + end + + def spec_not_found(gem_name) + raise GemNotFound, Bundler::CLI::Common.gem_not_found_message(gem_name, Bundler.definition.dependencies) + end + def print_gem_path(spec) Bundler.ui.info spec.full_gem_path end @@ -35,6 +44,7 @@ module Bundler gem_info << "\tSummary: #{spec.summary}\n" if spec.summary gem_info << "\tHomepage: #{spec.homepage}\n" if spec.homepage gem_info << "\tPath: #{spec.full_gem_path}\n" + gem_info << "\tDefault Gem: yes" if spec.respond_to?(:default_gem?) && spec.default_gem? Bundler.ui.info gem_info end end |