Puppet Function: wmflib::php_ini
- Defined in:
- modules/wmflib/lib/puppet/functions/wmflib/php_ini.rb
- Function type:
- Ruby 4.x API
Overview
Function: wmflib::php_ini( hash $ini_settings [, hash $… ] )
Serialize a hash into php.ini-style format. Takes one or more hashes as arguments. If the argument list contains more than one hash, they are merged together. In case of duplicate keys, hashes to the right win.
Example
wmflib::php_ini({'server' => {'port' => 80}}) # => server.port = 80
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'modules/wmflib/lib/puppet/functions/wmflib/php_ini.rb', line 12 Puppet::Functions.create_function(:'wmflib::php_ini') do dispatch :php_ini do required_repeated_param "Hash", :data return_type "String" end def php_ini(*args) flat = args.map { |arg| ini_flatten(arg) }.inject(:merge) = flat.map do |k, vs| case vs when Array then vs.map { |v| "#{k}[#{v}] = #{ini_cast(v)}" } else "#{k} = #{ini_cast(vs)}" end end .flatten.sort.push("").join("\n") end def ini_flatten(map, prefix = nil) map.reduce({}) do |flat, (k, v)| k = [prefix, k].compact.join(".") flat.merge! v.is_a?(Hash) ? ini_flatten(v, k) : Hash[k, v] end end def ini_cast(v) v.include?(".") ? Float(v) : Integer(v) rescue v end end |