diff options
author | Phil Nash <philnash@gmail.com> | 2015-09-26 18:19:23 +0200 |
---|---|---|
committer | Phil Nash <philnash@gmail.com> | 2015-09-26 18:19:43 +0200 |
commit | 3b63d3e16af0781c9b72d6967cfd452bbd9863ad (patch) | |
tree | b4bc7aa37ed7b728d0b22d82d8cf5105ab3ddd5f | |
parent | b0eab6354a4230e095fcc16bb5923bbe5d7eb20c (diff) | |
download | bundler-3b63d3e16af0781c9b72d6967cfd452bbd9863ad.tar.gz |
Removes duplication from bundle clean command
-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 |