| Module | RSCM::LineEditor |
| In: |
lib/rscm/line_editor.rb
|
Comments out line by line if they match the line_regex. Does not comment out already commented out lines. If comment_template is nil, the matching lines will be deleted Returns true if at least one line is commented out or changed
# File lib/rscm/line_editor.rb, line 10
10: def comment_out(original, line_regex, comment_template, output)
11: did_comment_out = false
12: already_commented_exp = /^[#{comment_template}]/ unless comment_template.nil?
13: original.each_line do |line|
14: out_line = nil
15: if(line_regex =~ line)
16: if(already_commented_exp && already_commented_exp =~ line)
17: out_line = line
18: else
19: did_comment_out = true
20: out_line = "#{comment_template}#{line}" unless comment_template.nil?
21: end
22: else
23: out_line = line
24: end
25: output << out_line unless out_line.nil?
26: end
27: did_comment_out
28: end