1 # frozen_string_literal: true
5 attr_reader :options, :gem_name, :latest_specs
6 def initialize(options, gem_name)
9 @verbose = options[:verbose] || options[:outdated]
10 @latest_specs = fetch_latest_specs if @verbose
15 Bundler.definition.validate_runtime!
20 if gem_name == "bundler"
21 path = File.expand_path("../../..", __dir__)
23 spec = Bundler::CLI::Common.select_spec(gem_name, :regex_match)
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}"
30 return Bundler.ui.info(path)
34 Bundler.load.specs.sort_by(&:name).map do |s|
35 Bundler.ui.info s.full_gem_path
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})"
42 latest = latest_specs.find {|l| l.name == s.name }
43 Bundler.ui.info <<~END
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"}
58 def fetch_latest_specs
59 definition = Bundler.definition(true)
61 Bundler.ui.info "Fetching remote specs for outdated check...\n\n"
62 Bundler.ui.silence { definition.resolve_remotely! }
64 definition.resolve_with_cache!
70 def outdated?(current, latest)
71 return false unless latest
72 Gem::Version.new(current.version) < Gem::Version.new(latest.version)