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
3434
3535 def handle_create_with_match ( )
3636 regex = resource [ :match ] ? Regexp . new ( resource [ :match ] ) : nil
37- match_count = lines . select { | l | regex . match ( l ) } . size
37+ match_count = count_matches ( regex )
3838 if match_count > 1 && resource [ :multiple ] . to_s != 'true'
3939 raise Puppet ::Error , "More than one line in file '#{ resource [ :path ] } ' matches pattern '#{ resource [ :match ] } '"
4040 end
@@ -51,9 +51,7 @@ def handle_create_with_match()
5151
5252 def handle_create_with_after
5353 regex = Regexp . new ( resource [ :after ] )
54-
55- count = lines . count { |l | l . match ( regex ) }
56-
54+ count = count_matches ( regex )
5755 case count
5856 when 1 # find the line to put our line after
5957 File . open ( resource [ :path ] , 'w' ) do |fh |
@@ -71,6 +69,10 @@ def handle_create_with_after
7169 end
7270 end
7371
72+ def count_matches ( regex )
73+ lines . select { |l | l . match ( regex ) } . size
74+ end
75+
7476 ##
7577 # append the line to the file.
7678 #
You can’t perform that action at this time.
0 commit comments