Debian Codegraph @

lib/bundler/cli/show.rb

raw
1 # frozen_string_literal: true
2
3 module Bundler
4 class CLI::Show
5 attr_reader :options, :gem_name, :latest_specs
6 def initialize(options, gem_name)
7 @options = options
8 @gem_name = gem_name
9 @verbose = options[:verbose] || options[:outdated]
10 @latest_specs = fetch_latest_specs if @verbose
11 end
12
13 def run
14 Bundler.ui.silence do
15 Bundler.definition.validate_runtime!
16 Bundler.load.lock
17 end
18
19 if gem_name
20 if gem_name == "bundler"
21 path = File.expand_path("../../..", __dir__)
22 else
23 spec = Bundler::CLI::Common.select_spec(gem_name, :regex_match)
24 return unless spec
25 path = spec.full_gem_path
26 unless File.directory?(path)
27 return Bundler.ui.warn "The gem #{gem_name} has been deleted. It was installed at: #{path}"
28 end
29 end
30 return Bundler.ui.info(path)
31 end
32
33 if options[:paths]
34 Bundler.load.specs.sort_by(&:name).map do |s|
35 Bundler.ui.info s.full_gem_path
36 end
37 else
38 Bundler.ui.info "Gems included by the bundle:"
39 Bundler.load.specs.sort_by(&:name).each do |s|
40 desc = " * #{s.name} (#{s.version}#{s.git_version})"
41 if @verbose
42 latest = latest_specs.find {|l| l.name == s.name }
43 Bundler.ui.info <<~END
44 #{desc.lstrip}
45 \tSummary: #{s.summary || "No description available."}
46 \tHomepage: #{s.homepage || "No website available."}
47 \tStatus: #{outdated?(s, latest) ? "Outdated - #{s.version} < #{latest.version}" : "Up to date"}
48 END
49 else
50 Bundler.ui.info desc
51 end
52 end
53 end
54 end
55
56 private
57
58 def fetch_latest_specs
59 definition = Bundler.definition(true)
60 if options[:outdated]
61 Bundler.ui.info "Fetching remote specs for outdated check...\n\n"
62 Bundler.ui.silence { definition.resolve_remotely! }
63 else
64 definition.resolve_with_cache!
65 end
66 Bundler.reset!
67 definition.specs
68 end
69
70 def outdated?(current, latest)
71 return false unless latest
72 Gem::Version.new(current.version) < Gem::Version.new(latest.version)
73 end
74 end
75 end