88bd303f3b4a0d9aa03cb7f72da75e9615192f44
[mirror/dsa-puppet.git] / 3rdparty / modules / postgresql / lib / puppet / provider / postgresql_conf / parsed.rb
1 require 'puppet/provider/parsedfile'
2
3 Puppet::Type.type(:postgresql_conf).provide(
4   :parsed,
5   :parent => Puppet::Provider::ParsedFile,
6   :default_target => '/etc/postgresql.conf',
7   :filetype => :flat
8 ) do
9   desc "Set key/values in postgresql.conf."
10
11   text_line :comment, :match => /^\s*#/
12   text_line :blank, :match => /^\s*$/
13
14   record_line :parsed,
15     :fields   => %w{name value comment},
16     :optional => %w{comment},
17     :match    => /^\s*([\w\.]+)\s*=?\s*(.*?)(?:\s*#\s*(.*))?\s*$/,
18     :to_line  => proc { |h|
19
20       # simple string and numeric values don't need to be enclosed in quotes
21       if h[:value].is_a?(Numeric)
22         val = h[:value].to_s
23       else
24         val = h[:value]
25       end
26       dontneedquote = val.match(/^(\d+.?\d+|\w+)$/)
27       dontneedequal = h[:name].match(/^(include|include_if_exists)$/i)
28
29       str =  h[:name].downcase # normalize case
30       str += dontneedequal ? ' ' : ' = '
31       str += "'" unless dontneedquote && !dontneedequal
32       str += val
33       str += "'" unless dontneedquote && !dontneedequal
34       str += " # #{h[:comment]}" unless (h[:comment].nil? or h[:comment] == :absent)
35       str
36     },
37     :post_parse => proc { |h|
38       h[:name].downcase! # normalize case
39       h[:value].gsub!(/(^'|'$)/, '') # strip out quotes
40     }
41
42 end