Class: Bundler::CLI::Outdated

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, gems) ⇒ Outdated

Returns a new instance of Outdated.



7
8
9
10
# File 'lib/bundler/cli/outdated.rb', line 7

def initialize(options, gems)
  @options = options
  @gems = gems
end

Instance Attribute Details

#gemsObject (readonly)

Returns the value of attribute gems.



6
7
8
# File 'lib/bundler/cli/outdated.rb', line 6

def gems
  @gems
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/bundler/cli/outdated.rb', line 6

def options
  @options
end

Instance Method Details

#runObject



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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/bundler/cli/outdated.rb', line 12

def run
  check_for_deployment_mode

  sources = Array(options[:source])

  gems.each do |gem_name|
    Bundler::CLI::Common.select_spec(gem_name)
  end

  Bundler.definition.validate_ruby!
  current_specs = Bundler.ui.silence { Bundler.load.specs }
  current_dependencies = {}
  Bundler.ui.silence { Bundler.load.dependencies.each {|dep| current_dependencies[dep.name] = dep } }

  if gems.empty? && sources.empty?
    # We're doing a full update
    definition = Bundler.definition(true)
  else
    definition = Bundler.definition(:gems => gems, :sources => sources)
  end

  definition_resolution = proc { options["local"] ? definition.resolve_with_cache! : definition.resolve_remotely! }
  if options[:parseable]
    Bundler.ui.silence(&definition_resolution)
  else
    definition_resolution.call
  end

  Bundler.ui.info ""

  out_count = 0
  # Loop through the current specs
  gemfile_specs, dependency_specs = current_specs.partition {|spec| current_dependencies.key? spec.name }
  [gemfile_specs.sort_by(&:name), dependency_specs.sort_by(&:name)].flatten.each do |current_spec|
    next if !gems.empty? && !gems.include?(current_spec.name)

    dependency = current_dependencies[current_spec.name]

    if options["strict"]
      active_spec = definition.specs.detect {|spec| spec.name == current_spec.name }
    else
      active_spec = definition.index[current_spec.name].sort_by(&:version)
      if !current_spec.version.prerelease? && !options[:pre] && active_spec.size > 1
        active_spec = active_spec.delete_if {|b| b.respond_to?(:version) && b.version.prerelease? }
      end
      active_spec = active_spec.last

      if options[:major] || options[:minor] || options[:patch]
        update_present = update_present_via_semver_portions(current_spec, active_spec, options)
        active_spec = nil unless update_present
      end
    end

    next if active_spec.nil?

    gem_outdated = Gem::Version.new(active_spec.version) > Gem::Version.new(current_spec.version)
    git_outdated = current_spec.git_version != active_spec.git_version
    if gem_outdated || git_outdated
      unless options[:parseable]
        if out_count == 0
          if options["pre"]
            Bundler.ui.info "Outdated gems included in the bundle (including pre-releases):"
          else
            Bundler.ui.info "Outdated gems included in the bundle:"
          end
        end
      end

      spec_version    = "#{active_spec.version}#{active_spec.git_version}"
      current_version = "#{current_spec.version}#{current_spec.git_version}"
      dependency_version = %(, requested #{dependency.requirement}) if dependency && dependency.specific?

      if dependency && !options[:parseable]
        groups = dependency.groups.join(", ")
        pl = (dependency.groups.length > 1) ? "s" : ""
        groups = " in group#{pl} \"#{groups}\""
      end

      spec_outdated_info = "#{active_spec.name} (newest #{spec_version}, installed #{current_version}#{dependency_version})"
      if options[:parseable]
        Bundler.ui.info spec_outdated_info.to_s.rstrip
      else
        Bundler.ui.info "  * #{spec_outdated_info}#{groups}".rstrip
      end

      out_count += 1
    end
    Bundler.ui.debug "from #{active_spec.loaded_from}"
  end

  if out_count.zero?
    Bundler.ui.info "Bundle up to date!\n" unless options[:parseable]
  else
    exit 1
  end
end