aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bundler/injector.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bundler/injector.rb')
-rw-r--r--lib/bundler/injector.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/bundler/injector.rb b/lib/bundler/injector.rb
index 02c3e6189f..e9aa13a357 100644
--- a/lib/bundler/injector.rb
+++ b/lib/bundler/injector.rb
@@ -179,11 +179,11 @@ module Bundler
# @param [Pathname] gemfile_path The Gemfile from which to remove dependencies.
def remove_gems_from_gemfile(gems, gemfile_path)
patterns = /gem\s+(['"])#{Regexp.union(gems)}\1|gem\s*\((['"])#{Regexp.union(gems)}\2\)/
-
new_gemfile = []
multiline_removal = false
IO.readlines(gemfile_path).each do |line|
- if line.match(patterns)
+ match_data = line.match(patterns)
+ if match_data && is_not_within_comment?(line, match_data)
multiline_removal = line.rstrip.end_with?(",")
# skip lines which match the regex
next
@@ -207,6 +207,13 @@ module Bundler
new_gemfile.join.chomp
end
+ # @param [String] line Individual line of gemfile content.
+ # @param [MatchData] match_data Data about Regex match.
+ def is_not_within_comment?(line, match_data)
+ match_start_index = match_data.offset(0).first
+ !line[0..match_start_index].include?("#")
+ end
+
# @param [Array] gemfile Array of gemfile contents.
# @param [String] block_name Name of block name to look for.
def remove_nested_blocks(gemfile, block_name)