Class: CLI::Outdated

Inherits:
Object
  • Object
show all
Defined in:
lib/dependency_bumper/bundler/cli/outdated.rb

Instance Method Summary collapse

Instance Method Details



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/dependency_bumper/bundler/cli/outdated.rb', line 63

def print_gem(current_spec, active_spec, dependency)
  spec_version = "#{active_spec.version}#{active_spec.git_version}"
  if Bundler.ui.debug? && active_spec.loaded_from
    spec_version += " (from #{active_spec.loaded_from})"
  end
  current_version = "#{current_spec.version}#{current_spec.git_version}"

  if dependency&.specific?
    dependency_version = %(, requested #{dependency.requirement})
  end

  spec_outdated_info = "#{active_spec.name} (newest #{spec_version}, " \
  "installed #{current_version}#{dependency_version})"

  output_message = spec_outdated_info.to_s

  Bundler.ui.info output_message.rstrip
end


82
83
84
85
86
# File 'lib/dependency_bumper/bundler/cli/outdated.rb', line 82

def print_gems(gems_list)
  gems_list.each do |gem|
    print_gem(*gem.values_at(:current_spec, :active_spec, :dependency))
  end
end

#runObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/dependency_bumper/bundler/cli/outdated.rb', line 5

def run
  check_for_deployment_mode!

  Bundler.definition.validate_runtime!
  # this commands gets current gems
  current_specs = Bundler.ui.silence { Bundler.definition.resolve }

  current_dependencies = Bundler.ui.silence do
    Bundler.load.dependencies.map { |dep| [dep.name, dep] }.to_h
  end

  definition = gems.empty? && sources.empty? ? Bundler.definition(true) : Bunder.definition(gems: gems, sources: sources)

  Bundler::CLI::Common.configure_gem_version_promoter(
    Bundler.definition,
    options
  )

  options[:local] ? definition.resolve_with_cache! : definition.resolve_remotely!

  # Loop through the current specs
  gemfile_specs, dependency_specs = current_specs.partition do |spec|
    current_dependencies.key? spec.name
  end

  specs = gemfile_specs + dependency_specs

  specs.sort_by(&:name).each do |current_spec|
    next unless gems.empty? || gems.include?(current_spec.name)

    active_spec = retrieve_active_spec(definition, current_spec)
    next unless active_spec

    unless filter_options_patch.empty? || update_present_via_semver_portions(current_spec, active_spec, options)
      next
    end

    gem_outdated = Gem::Version.new(active_spec.version) > Gem::Version.new(current_spec.version)
    unless gem_outdated || (current_spec.git_version != active_spec.git_version)
      next
    end

    dependency = current_dependencies[current_spec.name]

    outdated_gems_list << {
      active_spec: active_spec,
      current_spec: current_spec,
      dependency: dependency
    }
  end

  return [] if outdated_gems_list.empty?

  print_gems(outdated_gems_list)

  outdated_gems_list
end