File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed
lib/puppet/provider/file_line Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ def lines
34
34
35
35
def handle_create_with_match ( )
36
36
regex = resource [ :match ] ? Regexp . new ( resource [ :match ] ) : nil
37
- match_count = lines . select { | l | regex . match ( l ) } . size
37
+ match_count = count_matches ( regex )
38
38
if match_count > 1 && resource [ :multiple ] . to_s != 'true'
39
39
raise Puppet ::Error , "More than one line in file '#{ resource [ :path ] } ' matches pattern '#{ resource [ :match ] } '"
40
40
end
@@ -51,9 +51,7 @@ def handle_create_with_match()
51
51
52
52
def handle_create_with_after
53
53
regex = Regexp . new ( resource [ :after ] )
54
-
55
- count = lines . count { |l | l . match ( regex ) }
56
-
54
+ count = count_matches ( regex )
57
55
case count
58
56
when 1 # find the line to put our line after
59
57
File . open ( resource [ :path ] , 'w' ) do |fh |
@@ -71,6 +69,10 @@ def handle_create_with_after
71
69
end
72
70
end
73
71
72
+ def count_matches ( regex )
73
+ lines . select { |l | l . match ( regex ) } . size
74
+ end
75
+
74
76
##
75
77
# append the line to the file.
76
78
#
You can’t perform that action at this time.
0 commit comments