diff options
Diffstat (limited to 'lib/bundler/injector.rb')
-rw-r--r-- | lib/bundler/injector.rb | 51 |
1 files changed, 34 insertions, 17 deletions
diff --git a/lib/bundler/injector.rb b/lib/bundler/injector.rb index 6cb30b0eda..5c96884201 100644 --- a/lib/bundler/injector.rb +++ b/lib/bundler/injector.rb @@ -61,27 +61,16 @@ module Bundler # @param [Pathname] lockfile_path The lockfile from which to remove dependencies. # @return [Array] def remove(gemfile_path, lockfile_path) - # get initial gemfile snap shot - initial_gemfile = IO.readlines(gemfile_path) - - # evaluate the Gemfile we have + # evaluate the main Gemfile builder = Dsl.new builder.eval_gemfile(Bundler.default_gemfile) - # remove gems from dependencies - removed_deps = remove_gems_from_dependencies(builder, @deps) + definition = builder.to_definition(lockfile_path, {}) - # gemfile after removing requested gems - cleaned_gemfile = remove_gems_from_gemfile(@deps, gemfile_path) - - # write the new gemfile - write_to_gemfile(gemfile_path, cleaned_gemfile) - - # check for errors - # including extra gems being removed - # or some gems not being removed - # and return the actual removed deps - cross_check_for_errors(gemfile_path, builder.dependencies, removed_deps, initial_gemfile) + definition.gemfiles.each do |g| + # print success for removed gems + evaluate_gemfile(g).each {|dep| Bundler.ui.confirm "#{SharedHelpers.pretty_dependency(dep, false, true)} was removed." } + end end private @@ -133,6 +122,34 @@ module Bundler end end + # evalutes a gemfile to remove the specified gem + # from it. + def evaluate_gemfile(gemfile_path) + # get initial gemfile snap shot + initial_gemfile = IO.readlines(gemfile_path) + + Bundler.ui.info "Removing gems from #{gemfile_path}" + + # evaluate the Gemfile we have + builder = Dsl.new + builder.eval_gemfile(Bundler.default_gemfile) + + # remove gems from dependencies + removed_deps = remove_gems_from_dependencies(builder, @deps) + + # gemfile after removing requested gems + cleaned_gemfile = remove_gems_from_gemfile(@deps, gemfile_path) + + # write the new gemfile + write_to_gemfile(gemfile_path, cleaned_gemfile) + + # check for errors + # including extra gems being removed + # or some gems not being removed + # and return the actual removed deps + cross_check_for_errors(gemfile_path, builder.dependencies, removed_deps, initial_gemfile) + end + # @param [Dsl] builder Dsl object of current Gemfile. # @param [Array] gems Array of names of gems to be removed. # @return [Array] removed_deps Array of removed dependencies. |