File: package_options.rb

package info (click to toggle)
puppet-agent 8.10.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,404 kB
  • sloc: ruby: 286,820; sh: 492; xml: 116; makefile: 88; cs: 68
file content (33 lines) | stat: -rw-r--r-- 867 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# frozen_string_literal: true

require_relative '../../puppet/parameter'

# This specialized {Puppet::Parameter} handles munging of package options.
# Package options are passed as an array of key value pairs. Special munging is
# required as the keys and values needs to be quoted in a safe way.
#
class Puppet::Parameter::PackageOptions < Puppet::Parameter
  def unsafe_munge(values)
    values = [values] unless values.is_a? Array

    values.collect do |val|
      case val
      when Hash
        safe_hash = {}
        val.each_pair do |k, v|
          safe_hash[quote(k)] = quote(v)
        end
        safe_hash
      when String
        quote(val)
      else
        fail(_("Expected either a string or hash of options"))
      end
    end
  end

  # @api private
  def quote(value)
    value.include?(' ') ? %Q("#{value.gsub(/"/, '\"')}") : value
  end
end