summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHunter Haugen <hunter@puppetlabs.com>2014-09-16 14:30:10 -0700
committerHunter Haugen <hunter@puppetlabs.com>2014-09-16 14:30:10 -0700
commitc1ff630b169e2a249f6b47d408a3e90e26330cd3 (patch)
treeda55c76dcb05b18ec620ea5a5bbc8363c727c241
parent4a79fd063a57eb06a682abca0afc1d33a79c653b (diff)
parentacf435d1ce5916f99a13ef12f5f6560c9e63b935 (diff)
Merge pull request #321 from cyberious/4.3.x
MODULES-1248 Fix issue with not properly counting regex matches with leg...
-rw-r--r--lib/puppet/provider/file_line/ruby.rb10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/puppet/provider/file_line/ruby.rb b/lib/puppet/provider/file_line/ruby.rb
index 94e7fac..ae1a8b3 100644
--- a/lib/puppet/provider/file_line/ruby.rb
+++ b/lib/puppet/provider/file_line/ruby.rb
@@ -34,7 +34,7 @@ Puppet::Type.type(:file_line).provide(:ruby) do
def handle_create_with_match()
regex = resource[:match] ? Regexp.new(resource[:match]) : nil
- match_count = lines.select { |l| regex.match(l) }.size
+ match_count = count_matches(regex)
if match_count > 1 && resource[:multiple].to_s != 'true'
raise Puppet::Error, "More than one line in file '#{resource[:path]}' matches pattern '#{resource[:match]}'"
end
@@ -51,9 +51,7 @@ Puppet::Type.type(:file_line).provide(:ruby) do
def handle_create_with_after
regex = Regexp.new(resource[:after])
-
- count = lines.count {|l| l.match(regex)}
-
+ count = count_matches(regex)
case count
when 1 # find the line to put our line after
File.open(resource[:path], 'w') do |fh|
@@ -71,6 +69,10 @@ Puppet::Type.type(:file_line).provide(:ruby) do
end
end
+ def count_matches(regex)
+ lines.select{|l| l.match(regex)}.size
+ end
+
##
# append the line to the file.
#