1 require 'puppet/provider/parsedfile'
3 Puppet::Type.type(:postgresql_conf).provide(
5 :parent => Puppet::Provider::ParsedFile,
6 :default_target => '/etc/postgresql.conf',
9 desc "Set key/values in postgresql.conf."
11 text_line :comment, :match => /^\s*#/
12 text_line :blank, :match => /^\s*$/
15 :fields => %w{name value comment},
16 :optional => %w{comment},
17 :match => /^\s*([\w\.]+)\s*=?\s*(.*?)(?:\s*#\s*(.*))?\s*$/,
18 :to_line => proc { |h|
20 # simple string and numeric values don't need to be enclosed in quotes
21 if h[:value].is_a?(Numeric)
26 dontneedquote = val.match(/^(\d+.?\d+|\w+)$/)
27 dontneedequal = h[:name].match(/^(include|include_if_exists)$/i)
29 str = h[:name].downcase # normalize case
30 str += dontneedequal ? ' ' : ' = '
31 str += "'" unless dontneedquote && !dontneedequal
33 str += "'" unless dontneedquote && !dontneedequal
34 str += " # #{h[:comment]}" unless (h[:comment].nil? or h[:comment] == :absent)
37 :post_parse => proc { |h|
38 h[:name].downcase! # normalize case
39 h[:value].gsub!(/(^'|'$)/, '') # strip out quotes