From 69bee117fbd0aa9d05bdc73cd370dc5c5dc80876 Mon Sep 17 00:00:00 2001 From: Guillermo Guerrero Date: Fri, 12 Apr 2019 18:32:42 +0200 Subject: Move duplicated code to `before` blocks --- spec/commands/outdated_spec.rb | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/spec/commands/outdated_spec.rb b/spec/commands/outdated_spec.rb index 5a60b564b8..ab54925756 100644 --- a/spec/commands/outdated_spec.rb +++ b/spec/commands/outdated_spec.rb @@ -76,7 +76,7 @@ RSpec.describe "bundle outdated" do end describe "with --group option" do - def test_group_option(group = nil, gems_list_size = 1) + before do install_gemfile <<-G source "#{file_uri_for(gem_repo2)}" @@ -87,7 +87,9 @@ RSpec.describe "bundle outdated" do gem 'activesupport', '2.3.5' end G + end + def test_group_option(group = nil, gems_list_size = 1) update_repo2 do build_gem "activesupport", "3.0" build_gem "terranova", "9" @@ -103,17 +105,6 @@ RSpec.describe "bundle outdated" do end it "not outdated gems" do - install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - - gem "weakling", "~> 0.0.1" - gem "terranova", '8' - group :development, :test do - gem 'activesupport', '2.3.5' - gem "duradura", '7.0' - end - G - bundle "outdated --group" expect(out).to include("Bundle up to date!") end @@ -153,7 +144,7 @@ RSpec.describe "bundle outdated" do end describe "with --groups option" do - it "not outdated gems" do + before do install_gemfile <<-G source "#{file_uri_for(gem_repo2)}" @@ -164,23 +155,14 @@ RSpec.describe "bundle outdated" do gem "duradura", '7.0' end G + end + it "not outdated gems" do bundle "outdated --groups" expect(out).to include("Bundle up to date!") end it "returns a sorted list of outdated gems by groups" do - install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - - gem "weakling", "~> 0.0.1" - gem "terranova", '8' - group :development, :test do - gem 'activesupport', '2.3.5' - gem "duradura", '7.0' - end - G - update_repo2 do build_gem "activesupport", "3.0" build_gem "terranova", "9" -- cgit v1.2.1 From 832fb900f092faf0e6ae6937d98384f8d61e5336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 24 Jul 2019 13:30:56 +0200 Subject: Move `options_include_groups` to an attribute MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Guillermo Guerrero Co-authored-by: David Rodríguez --- lib/bundler/cli/outdated.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb index 2075fe83c8..4fa41a7a6f 100644 --- a/lib/bundler/cli/outdated.rb +++ b/lib/bundler/cli/outdated.rb @@ -2,11 +2,15 @@ module Bundler class CLI::Outdated - attr_reader :options, :gems + attr_reader :options, :gems, :options_include_groups def initialize(options, gems) @options = options @gems = gems + + @options_include_groups = [:group, :groups].select do |v| + options.keys.include?(v.to_s) + end end def run @@ -115,10 +119,6 @@ module Bundler end end - options_include_groups = [:group, :groups].select do |v| - options.keys.include?(v.to_s) - end - if options_include_groups.any? ordered_groups = outdated_gems_by_groups.keys.compact.sort [nil, ordered_groups].flatten.each do |groups| -- cgit v1.2.1 From 53c0fae760e9fb22aa9b014785bc9e098c1424ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 24 Jul 2019 13:34:52 +0200 Subject: Move `any?` logic to the attribute MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's the only usage of the `options_include_groups` attribute and its name suggests a boolean, so it fits better now. Co-authored-by: Guillermo Guerrero Co-authored-by: David Rodríguez --- lib/bundler/cli/outdated.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb index 4fa41a7a6f..edff072199 100644 --- a/lib/bundler/cli/outdated.rb +++ b/lib/bundler/cli/outdated.rb @@ -8,7 +8,7 @@ module Bundler @options = options @gems = gems - @options_include_groups = [:group, :groups].select do |v| + @options_include_groups = [:group, :groups].any? do |v| options.keys.include?(v.to_s) end end @@ -119,7 +119,7 @@ module Bundler end end - if options_include_groups.any? + if options_include_groups ordered_groups = outdated_gems_by_groups.keys.compact.sort [nil, ordered_groups].flatten.each do |groups| gems = outdated_gems_by_groups[groups] @@ -145,7 +145,6 @@ module Bundler gem[:active_spec], gem[:dependency], groups, - options_include_groups.any? ) end end @@ -156,7 +155,6 @@ module Bundler gem[:active_spec], gem[:dependency], gem[:groups], - options_include_groups.any? ) end end @@ -201,7 +199,7 @@ module Bundler end end - def print_gem(current_spec, active_spec, dependency, groups, options_include_groups) + def print_gem(current_spec, active_spec, dependency, groups) spec_version = "#{active_spec.version}#{active_spec.git_version}" spec_version += " (from #{active_spec.loaded_from})" if Bundler.ui.debug? && active_spec.loaded_from current_version = "#{current_spec.version}#{current_spec.git_version}" -- cgit v1.2.1 From 4335df3e4c4853c505dbc21d896a418d6f942643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 24 Jul 2019 13:38:47 +0200 Subject: Move more locals to attributes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Guillermo Guerrero Co-authored-by: David Rodríguez --- lib/bundler/cli/outdated.rb | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb index edff072199..72f8e65a20 100644 --- a/lib/bundler/cli/outdated.rb +++ b/lib/bundler/cli/outdated.rb @@ -2,11 +2,19 @@ module Bundler class CLI::Outdated - attr_reader :options, :gems, :options_include_groups + attr_reader :options, :gems, :options_include_groups, :filter_options_patch, :sources + attr_accessor :outdated_gems_by_groups, :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] + + @outdated_gems_by_groups = {} + @outdated_gems_list = [] @options_include_groups = [:group, :groups].any? do |v| options.keys.include?(v.to_s) @@ -16,8 +24,6 @@ module Bundler def run check_for_deployment_mode - sources = Array(options[:source]) - gems.each do |gem_name| Bundler::CLI::Common.select_spec(gem_name) end @@ -48,9 +54,6 @@ module Bundler strict = options["filter-strict"] || Bundler::CLI::Common.patch_level_options(options).any? - filter_options_patch = options.keys & - %w[filter-major filter-minor filter-patch] - definition_resolution = proc do options[:local] ? definition.resolve_with_cache! : definition.resolve_remotely! end @@ -62,8 +65,6 @@ module Bundler end Bundler.ui.info "" - outdated_gems_by_groups = {} - outdated_gems_list = [] # Loop through the current specs gemfile_specs, dependency_specs = current_specs.partition do |spec| @@ -108,7 +109,7 @@ module Bundler end if outdated_gems_list.empty? - display_nothing_outdated_message(filter_options_patch) + display_nothing_outdated_message else unless options[:parseable] if options[:pre] @@ -185,7 +186,7 @@ module Bundler active_spec end - def display_nothing_outdated_message(filter_options_patch) + def display_nothing_outdated_message unless options[:parseable] if filter_options_patch.any? display = filter_options_patch.map do |o| -- cgit v1.2.1 From be9d6e7cfca02c91d045448aa742cdd79e336c20 Mon Sep 17 00:00:00 2001 From: Guillermo Guerrero Date: Fri, 12 Apr 2019 18:52:52 +0200 Subject: Less complexity --- lib/bundler/cli/outdated.rb | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb index 72f8e65a20..e583010d4b 100644 --- a/lib/bundler/cli/outdated.rb +++ b/lib/bundler/cli/outdated.rb @@ -30,11 +30,9 @@ module Bundler Bundler.definition.validate_runtime! current_specs = Bundler.ui.silence { Bundler.definition.resolve } - current_dependencies = {} - Bundler.ui.silence do - Bundler.load.dependencies.each do |dep| - current_dependencies[dep.name] = dep - end + + current_dependencies = Bundler.ui.silence do + Bundler.load.dependencies.map {|dep| [dep.name, dep] }.to_h end definition = if gems.empty? && sources.empty? @@ -84,10 +82,8 @@ module Bundler active_spec = retrieve_active_spec(strict, definition, current_spec) next if active_spec.nil? - if filter_options_patch.any? - update_present = update_present_via_semver_portions(current_spec, active_spec, options) - next unless update_present - end + next if filter_options_patch.any? && + !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) @@ -102,10 +98,7 @@ module Bundler :groups => groups } outdated_gems_by_groups[groups] ||= [] - outdated_gems_by_groups[groups] << { :active_spec => active_spec, - :current_spec => current_spec, - :dependency => dependency, - :groups => groups } + outdated_gems_by_groups[groups] << outdated_gems_list[-1] end if outdated_gems_list.empty? @@ -122,7 +115,7 @@ module Bundler if options_include_groups ordered_groups = outdated_gems_by_groups.keys.compact.sort - [nil, ordered_groups].flatten.each do |groups| + ordered_groups.insert(0, nil).each do |groups| gems = outdated_gems_by_groups[groups] contains_group = if groups groups.split(", ").include?(options[:group]) @@ -265,7 +258,7 @@ module Bundler def get_version_semver_portion_value(spec, version_portion_index) version_section = spec.version.segments[version_portion_index, 1] - version_section.nil? ? 0 : (version_section.first || 0) + version_section.to_a[0].to_i end end end -- cgit v1.2.1 From 0d8c8d207e9508eb6f5bdd3d479daabb962c5593 Mon Sep 17 00:00:00 2001 From: Guillermo Guerrero Date: Fri, 12 Apr 2019 18:59:35 +0200 Subject: Extract a `print_gems` method --- lib/bundler/cli/outdated.rb | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb index e583010d4b..6389f909e1 100644 --- a/lib/bundler/cli/outdated.rb +++ b/lib/bundler/cli/outdated.rb @@ -133,24 +133,10 @@ module Bundler end end - gems.each do |gem| - print_gem( - gem[:current_spec], - gem[:active_spec], - gem[:dependency], - groups, - ) - end + print_gems(gems) end else - outdated_gems_list.each do |gem| - print_gem( - gem[:current_spec], - gem[:active_spec], - gem[:dependency], - gem[:groups], - ) - end + print_gems(outdated_gems_list) end exit 1 @@ -193,6 +179,17 @@ module Bundler end end + def print_gems(gems_list) + gems_list.each do |gem| + print_gem( + gem[:current_spec], + gem[:active_spec], + gem[:dependency], + gem[:groups], + ) + end + end + def print_gem(current_spec, active_spec, dependency, groups) spec_version = "#{active_spec.version}#{active_spec.git_version}" spec_version += " (from #{active_spec.loaded_from})" if Bundler.ui.debug? && active_spec.loaded_from -- cgit v1.2.1 From d845a213ca7745f05a3faba734be79f418275791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 24 Jul 2019 16:03:46 +0200 Subject: Unfold message to single line for readability --- lib/bundler/cli/outdated.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb index 6389f909e1..804e8072d4 100644 --- a/lib/bundler/cli/outdated.rb +++ b/lib/bundler/cli/outdated.rb @@ -106,8 +106,7 @@ module Bundler else unless options[:parseable] if options[:pre] - Bundler.ui.info "Outdated gems included in the bundle (including " \ - "pre-releases):" + Bundler.ui.info "Outdated gems included in the bundle (including pre-releases):" else Bundler.ui.info "Outdated gems included in the bundle:" end -- cgit v1.2.1 From 027aba0cfff0214f69eee4e1636e9ef90a40488b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 24 Jul 2019 16:09:35 +0200 Subject: Extract some methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Guillermo Guerrero Co-authored-by: David Rodríguez --- lib/bundler/cli/outdated.rb | 50 ++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb index 804e8072d4..ad58be0b9f 100644 --- a/lib/bundler/cli/outdated.rb +++ b/lib/bundler/cli/outdated.rb @@ -105,11 +105,7 @@ module Bundler display_nothing_outdated_message else unless options[:parseable] - 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 + Bundler.ui.info(header_outdated_message) end if options_include_groups @@ -125,11 +121,7 @@ module Bundler next if (!options[:groups] && !contains_group) || gems.nil? unless options[:parseable] - if groups - Bundler.ui.info "===== #{groups_text("Group", groups)} =====" - else - Bundler.ui.info "===== Without group =====" - end + Bundler.ui.info(header_group_message(groups)) end print_gems(gems) @@ -148,6 +140,34 @@ module Bundler "#{group_text}#{groups.split(",").size > 1 ? "s" : ""} \"#{groups}\"" end + def header_outdated_message + if options[:pre] + "Outdated gems included in the bundle (including pre-releases):" + else + "Outdated gems included in the bundle:" + end + end + + def header_group_message(groups) + if groups + "===== #{groups_text("Group", groups)} =====" + else + "===== Without group =====" + end + end + + def nothing_outdated_message + if filter_options_patch.any? + display = filter_options_patch.map do |o| + o.sub("filter-", "") + end.join(" or ") + + "No #{display} updates to display.\n" + else + "Bundle up to date!\n" + end + end + def retrieve_active_spec(strict, definition, current_spec) return unless current_spec.match_platform(Bundler.local_platform) @@ -166,15 +186,7 @@ module Bundler def display_nothing_outdated_message unless options[:parseable] - if filter_options_patch.any? - display = filter_options_patch.map do |o| - o.sub("filter-", "") - end.join(" or ") - - Bundler.ui.info "No #{display} updates to display.\n" - else - Bundler.ui.info "Bundle up to date!\n" - end + Bundler.ui.info(nothing_outdated_message) end end -- cgit v1.2.1 From 7b68d86bddaf40530bbb0957e8631716c4b46566 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 24 Jul 2019 13:00:30 +0200 Subject: Move `strict` to an attribute MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Guillermo Guerrero Co-authored-by: David Rodríguez --- lib/bundler/cli/outdated.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb index ad58be0b9f..e35031a4ff 100644 --- a/lib/bundler/cli/outdated.rb +++ b/lib/bundler/cli/outdated.rb @@ -2,7 +2,7 @@ module Bundler class CLI::Outdated - attr_reader :options, :gems, :options_include_groups, :filter_options_patch, :sources + attr_reader :options, :gems, :options_include_groups, :filter_options_patch, :sources, :strict attr_accessor :outdated_gems_by_groups, :outdated_gems_list def initialize(options, gems) @@ -19,6 +19,11 @@ module Bundler @options_include_groups = [:group, :groups].any? do |v| options.keys.include?(v.to_s) end + + # 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? end def run @@ -47,11 +52,6 @@ module Bundler options ) - # 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? - definition_resolution = proc do options[:local] ? definition.resolve_with_cache! : definition.resolve_remotely! end @@ -79,7 +79,7 @@ module Bundler next if !gems.empty? && !gems.include?(current_spec.name) dependency = current_dependencies[current_spec.name] - active_spec = retrieve_active_spec(strict, definition, current_spec) + active_spec = retrieve_active_spec(definition, current_spec) next if active_spec.nil? next if filter_options_patch.any? && @@ -168,7 +168,7 @@ module Bundler end end - def retrieve_active_spec(strict, definition, current_spec) + def retrieve_active_spec(definition, current_spec) return unless current_spec.match_platform(Bundler.local_platform) if strict -- cgit v1.2.1 From 584e841624720024075b2f418ae030135428a172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 24 Jul 2019 13:00:46 +0200 Subject: Add exclamation mark to method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To indicate that it can raise. Co-authored-by: Guillermo Guerrero Co-authored-by: David Rodríguez --- lib/bundler/cli/outdated.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb index e35031a4ff..5c8cd26d88 100644 --- a/lib/bundler/cli/outdated.rb +++ b/lib/bundler/cli/outdated.rb @@ -27,7 +27,7 @@ module Bundler end def run - check_for_deployment_mode + check_for_deployment_mode! gems.each do |gem_name| Bundler::CLI::Common.select_spec(gem_name) @@ -224,7 +224,7 @@ module Bundler Bundler.ui.info output_message.rstrip end - def check_for_deployment_mode + def check_for_deployment_mode! return unless Bundler.frozen_bundle? suggested_command = if Bundler.settings.locations("frozen")[:global] "bundle config unset frozen" -- cgit v1.2.1