Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Merge #7365
Browse files Browse the repository at this point in the history
7365: Refactor `bundle outdated` r=deivid-rodriguez a=deivid-rodriguez

### What was the end-user problem that led to this PR?

The problem was that while working on a better `bundle outdated` format (essentially getting #4474 ready to merge), I noticed a bunch of logic in `bundle outdated` that's overly complicated and not necessary.

### What was your diagnosis of the problem?

My diagnosis was that I should simplify the implementation before changing the output.

### What is your fix for the problem, implemented in this PR?

My fix is to add my improvements as a separate PR. Afterwards I'll rebase and get #4474 ready.

### Why did you choose this fix out of the possible options?

I chose this fix because including this improvements with #4474 made that PR too big and hard to understand.

Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net>
  • Loading branch information
bundlerbot and deivid-rodriguez committed Sep 26, 2019
2 parents a598871 + b7bc8d4 commit 1da170e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 33 deletions.
37 changes: 12 additions & 25 deletions lib/bundler/cli/outdated.rb
Expand Up @@ -3,17 +3,15 @@
module Bundler
class CLI::Outdated
attr_reader :options, :gems, :options_include_groups, :filter_options_patch, :sources, :strict
attr_accessor :outdated_gems_by_groups, :outdated_gems_list
attr_accessor :outdated_gems_list

def initialize(options, gems)
@options = options
@gems = gems
@sources = Array(options[:source])

@filter_options_patch = options.keys &
%w[filter-major filter-minor filter-patch]
@filter_options_patch = options.keys & %w[filter-major filter-minor filter-patch]

@outdated_gems_by_groups = {}
@outdated_gems_list = []

@options_include_groups = [:group, :groups].any? do |v|
Expand All @@ -22,8 +20,7 @@ def initialize(options, gems)

# the patch level options imply strict is also true. It wouldn't make
# sense otherwise.
@strict = options["filter-strict"] ||
Bundler::CLI::Common.patch_level_options(options).any?
@strict = options["filter-strict"] || Bundler::CLI::Common.patch_level_options(options).any?
end

def run
Expand Down Expand Up @@ -76,17 +73,15 @@ def run
end

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

dependency = current_dependencies[current_spec.name]
active_spec = retrieve_active_spec(definition, current_spec)

next if active_spec.nil?
next if filter_options_patch.any? &&
!update_present_via_semver_portions(current_spec, active_spec, options)
next unless filter_options_patch.empty? || update_present_via_semver_portions(current_spec, active_spec, options)

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

dependency = current_dependencies[current_spec.name]
groups = nil
if dependency && !options[:parseable]
groups = dependency.groups.join(", ")
Expand All @@ -96,9 +91,6 @@ def run
:current_spec => current_spec,
:dependency => dependency,
:groups => groups }

outdated_gems_by_groups[groups] ||= []
outdated_gems_by_groups[groups] << outdated_gems_list[-1]
end

if outdated_gems_list.empty?
Expand All @@ -109,16 +101,9 @@ def run
end

if options_include_groups
ordered_groups = outdated_gems_by_groups.keys.compact.sort
ordered_groups.insert(0, nil).each do |groups|
gems = outdated_gems_by_groups[groups]
contains_group = if groups
groups.split(", ").include?(options[:group])
else
options[:group] == "group"
end

next if (!options[:groups] && !contains_group) || gems.nil?
outdated_gems_list.group_by {|g| g[:groups] }.sort.each do |groups, gems|
contains_group = groups.split(", ").include?(options[:group])
next unless options[:groups] || contains_group

unless options[:parseable]
Bundler.ui.info(header_group_message(groups))
Expand Down Expand Up @@ -239,6 +224,8 @@ def check_for_deployment_mode!
end

def update_present_via_semver_portions(current_spec, active_spec, options)
return false if active_spec.nil?

current_major = current_spec.version.segments.first
active_major = active_spec.version.segments.first

Expand Down
16 changes: 8 additions & 8 deletions spec/commands/outdated_spec.rb
Expand Up @@ -658,19 +658,19 @@ def test_group_option(group = nil, gems_list_size = 1)

# establish a lockfile set to 1.0.0
install_gemfile <<-G
source "#{file_uri_for(gem_repo4)}"
gem 'patch', '1.0.0'
gem 'minor', '1.0.0'
gem 'major', '1.0.0'
source "#{file_uri_for(gem_repo4)}"
gem 'patch', '1.0.0'
gem 'minor', '1.0.0'
gem 'major', '1.0.0'
G

# remove 1.4.3 requirement and bar altogether
# to setup update specs below
gemfile <<-G
source "#{file_uri_for(gem_repo4)}"
gem 'patch'
gem 'minor'
gem 'major'
source "#{file_uri_for(gem_repo4)}"
gem 'patch'
gem 'minor'
gem 'major'
G
end

Expand Down

0 comments on commit 1da170e

Please sign in to comment.