diff options
author | Homu <homu@barosl.com> | 2015-09-27 04:37:47 +0900 |
---|---|---|
committer | Homu <homu@barosl.com> | 2015-09-27 04:37:47 +0900 |
commit | 20f04aa8923c0d0f02e7a74d5e9609d772351668 (patch) | |
tree | b4bc7aa37ed7b728d0b22d82d8cf5105ab3ddd5f | |
parent | b0eab6354a4230e095fcc16bb5923bbe5d7eb20c (diff) | |
parent | 3b63d3e16af0781c9b72d6967cfd452bbd9863ad (diff) | |
download | bundler-20f04aa8923c0d0f02e7a74d5e9609d772351668.tar.gz |
Auto merge of #4018 - philnash:removing_duplication, r=segiddins
Removes duplication from bundle clean command
I was not feeling inspired, but I do like to delete code! Here's a small simplification as reported [in Code Climate](https://codeclimate.com/github/bundler/bundler/Bundler::Runtime).
-rw-r--r-- | lib/bundler/runtime.rb | 59 |
1 files changed, 23 insertions, 36 deletions
diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index 5e87ee7cc3..d0b81d6624 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -171,44 +171,13 @@ module Bundler stale_gem_files = gem_files - spec_cache_paths stale_gemspec_files = gemspec_files - spec_gemspec_paths - output = stale_gem_dirs.collect do |gem_dir| - full_name = Pathname.new(gem_dir).basename.to_s - - parts = full_name.split("-") - name = parts[0..-2].join("-") - version = parts.last - output = "#{name} (#{version})" - - if dry_run - Bundler.ui.info "Would have removed #{output}" - else - Bundler.ui.info "Removing #{output}" - FileUtils.rm_rf(gem_dir) - end - - output - end + stale_git_dirs.collect do |gem_dir| - full_name = Pathname.new(gem_dir).basename.to_s - - parts = full_name.split("-") - name = parts[0..-2].join("-") - revision = parts[-1] - output = "#{name} (#{revision})" - - if dry_run - Bundler.ui.info "Would have removed #{output}" - else - Bundler.ui.info "Removing #{output}" - FileUtils.rm_rf(gem_dir) - end - - output - end + removed_stale_gem_dirs = stale_gem_dirs.collect {|dir| remove_dir(dir, dry_run) } + removed_stale_git_dirs = stale_git_dirs.collect {|dir| remove_dir(dir, dry_run) } + output = removed_stale_gem_dirs + removed_stale_git_dirs unless dry_run - stale_gem_bins.each {|bin| FileUtils.rm(bin) if File.exist?(bin) } - stale_gem_files.each {|file| FileUtils.rm(file) if File.exist?(file) } - stale_gemspec_files.each {|file| FileUtils.rm(file) if File.exist?(file) } + stale_files = stale_gem_bins + stale_gem_files + stale_gemspec_files + stale_files.each {|file| FileUtils.rm(file) if File.exist?(file) } stale_git_cache_dirs.each {|dir| FileUtils.rm_rf(dir) if File.exist?(dir) } end @@ -290,5 +259,23 @@ module Bundler ).uniq.join(File::PATH_SEPARATOR) end end + + def remove_dir(dir, dry_run) + full_name = Pathname.new(dir).basename.to_s + + parts = full_name.split("-") + name = parts[0..-2].join("-") + version = parts.last + output = "#{name} (#{version})" + + if dry_run + Bundler.ui.info "Would have removed #{output}" + else + Bundler.ui.info "Removing #{output}" + FileUtils.rm_rf(dir) + end + + output + end end end |