Module: TextFileMutator

Defined in:
lib/txt_file_mutator.rb

Class Method Summary collapse

Class Method Details

.comment_gem_config(file, line) ⇒ Object



14
15
16
17
18
# File 'lib/txt_file_mutator.rb', line 14

def self.comment_gem_config(file, line)  
  gsub_file file, /^\s*[^#]\s*config.gem.+'#{Regexp.escape(line)}'$/ do |match|
    "# " + "#{match}"
  end
end

.comment_line(file, line) ⇒ Object



26
27
28
29
30
# File 'lib/txt_file_mutator.rb', line 26

def self.comment_line(file, line)  
  gsub_file file, /^\s*[^#]\s*(#{Regexp.escape(line)}$)/i do |match|
    "# " + "#{match}"
  end
end

.insert_after(file, line, txt_after) ⇒ Object



8
9
10
11
12
# File 'lib/txt_file_mutator.rb', line 8

def self.insert_after(file, line, txt_after)  
  gsub_file file, /(#{Regexp.escape(line)})/ do |match|
    "#{match}\n#{txt_after}"
  end
end

.insert_before(file, line, txt_before) ⇒ Object



2
3
4
5
6
# File 'lib/txt_file_mutator.rb', line 2

def self.insert_before(file, line, txt_before)  
  gsub_file file, /(#{Regexp.escape(line)})/ do |match|
    "#{txt_before}\n#{match}"
  end
end

.remove_content(file, line) ⇒ Object



32
33
34
35
36
# File 'lib/txt_file_mutator.rb', line 32

def self.remove_content(file, line)  
  gsub_file file, /(#{Regexp.escape(line)})/i do |match|
    ""
  end
end

.remove_line(file, line) ⇒ Object



38
39
40
41
42
# File 'lib/txt_file_mutator.rb', line 38

def self.remove_line(file, line)  
  gsub_file file, /^.*#{Regexp.escape(line)}.*$)/i do |match|
    ""
  end
end

.remove_require(file, line) ⇒ Object



20
21
22
23
24
# File 'lib/txt_file_mutator.rb', line 20

def self.remove_require(file, line)
  gsub_file file, /^\s*require\s+'#{Regexp.escape(line)}'$/ do |match|
    ""
  end
end