summaryrefslogtreecommitdiff
path: root/lib/puppet/provider
diff options
context:
space:
mode:
authorAshley Penney <ashley.penney@puppetlabs.com>2014-05-15 17:31:28 -0400
committerAshley Penney <ashley.penney@puppetlabs.com>2014-05-15 17:31:28 -0400
commit645de3cccb8050c13ef35cdc855e831f65765e0a (patch)
tree239d09f3f93f35d3fc79f28499e19b65756ab982 /lib/puppet/provider
parent430d821ad3bc6828b9c0bc1ddf5967fdd4b4d66b (diff)
parentc5b06f9bbca7acc491560c92a73d7e2a153fe0a7 (diff)
downloadpuppet-stdlib-645de3cccb8050c13ef35cdc855e831f65765e0a.tar.gz
puppet-stdlib-645de3cccb8050c13ef35cdc855e831f65765e0a.tar.bz2
Merge pull request #257 from apenney/revert-before
Revert "Merge pull request #256 from stbenjam/2571-before"
Diffstat (limited to 'lib/puppet/provider')
-rw-r--r--lib/puppet/provider/file_line/ruby.rb16
1 files changed, 7 insertions, 9 deletions
diff --git a/lib/puppet/provider/file_line/ruby.rb b/lib/puppet/provider/file_line/ruby.rb
index 2cbd172..94e7fac 100644
--- a/lib/puppet/provider/file_line/ruby.rb
+++ b/lib/puppet/provider/file_line/ruby.rb
@@ -9,9 +9,7 @@ Puppet::Type.type(:file_line).provide(:ruby) do
if resource[:match]
handle_create_with_match
elsif resource[:after]
- handle_create_with_position :after
- elsif resource[:before]
- handle_create_with_position :before
+ handle_create_with_after
else
append_line
end
@@ -51,29 +49,29 @@ Puppet::Type.type(:file_line).provide(:ruby) do
end
end
- def handle_create_with_position(position)
- regex = resource[position] ? Regexp.new(resource[position]) : nil
+ def handle_create_with_after
+ regex = Regexp.new(resource[:after])
count = lines.count {|l| l.match(regex)}
case count
- when 1 # find the line to put our line before/after
+ when 1 # find the line to put our line after
File.open(resource[:path], 'w') do |fh|
lines.each do |l|
- fh.puts(l) if position == :after
+ fh.puts(l)
if regex.match(l) then
fh.puts(resource[:line])
end
- fh.puts(l) if position == :before
end
end
when 0 # append the line to the end of the file
append_line
else
- raise Puppet::Error, "#{count} lines match pattern '#{resource[position]}' in file '#{resource[:path]}'. One or no line must match the pattern."
+ raise Puppet::Error, "#{count} lines match pattern '#{resource[:after]}' in file '#{resource[:path]}'. One or no line must match the pattern."
end
end
+ ##
# append the line to the file.
#
# @api private