Skip to content

Commit 7f8a1d6

Browse files
author
Nuo Yan
committed
initial work (updated) chef-78
1 parent 91d8d1e commit 7f8a1d6

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

chef/lib/chef/util/FileEdit.rb

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class FileEdit
2-
2+
33
require 'ftools'
44

55
private
@@ -9,16 +9,13 @@ class FileEdit
99

1010
def initialize(filepath)
1111
@filename = filepath
12-
@contents = Array.new
1312
@match = false
1413

15-
1614
raise ArgumentError, "File doesn't exist" unless File.exist? @filename
1715
raise ArgumentError, "File is blank" unless (@contents = File.new(@filename).readlines).length > 0
1816

1917
end
2018

21-
2219
#search the file line by line and match each line with the given regex
2320
#if matched, replace the whole line with newline.
2421
def search_file_replace_line(regex, newline)
@@ -63,7 +60,6 @@ def write_file
6360
end
6461
@match = false
6562
end
66-
6763

6864
private
6965

@@ -74,7 +70,8 @@ def search_match(regex, replace, command, method)
7470

7571
#check if regex is Regexp object or simple string and store the Regexp object in exp.
7672
(regex.kind_of? Regexp)? exp = regex : exp = Regexp.new(regex)
77-
73+
74+
#loop through @contents and do the appropriate operation depending on 'command' and 'method'
7875
i = 0
7976
begin
8077
line = @contents[i]
@@ -97,8 +94,6 @@ def search_match(regex, replace, command, method)
9794
i = i+1
9895
end until i == @contents.length
9996
end
100-
101-
10297
end
10398

10499
#test

0 commit comments

Comments
 (0)