class Puppet::Parameter::Path

This specialized {Puppet::Parameter} handles validation and munging of paths. By default, a single path is accepted, and by calling {accept_arrays} it is possible to allow an array of paths.

Public Class Methods

accept_arrays(bool = true) click to toggle source

Specifies whether multiple paths are accepted or not. @dsl type

   # File lib/puppet/parameter/path.rb
11 def self.accept_arrays(bool = true)
12   @accept_arrays = !!bool
13 end
arrays?() click to toggle source
   # File lib/puppet/parameter/path.rb
14 def self.arrays?
15   @accept_arrays
16 end

Public Instance Methods

unsafe_munge(paths) click to toggle source

This is the default implementation of `munge`. If the concrete parameter defines a `munge` method, this default implementation will be overridden. This default implementation does not perform any munging, it just checks the one/many paths constraints. A derived implementation can perform this check as: `paths.is_a?(Array) and ! self.class.arrays?` and raise a {Puppet::Error}. @param paths [String, Array<String>] one of multiple paths @return [String, Array<String>] the given paths @raise [Puppet::Error] if the given paths does not comply with the on/many paths rule.

   # File lib/puppet/parameter/path.rb
51 def unsafe_munge(paths)
52   if paths.is_a?(Array) and ! self.class.arrays? then
53     fail _("%{name} only accepts a single path, not an array of paths") % { name: name }
54   end
55   paths
56 end
unsafe_validate(paths) click to toggle source

This is the default implementation of the `validate` method. It will be overridden if the validate option is used when defining the parameter. @return [void]

   # File lib/puppet/parameter/path.rb
39 def unsafe_validate(paths)
40   validate_path(paths)
41 end
validate_path(paths) click to toggle source

Performs validation of the given paths. If the concrete parameter defines a validation method, it may call this method to perform path validation. @raise [Puppet::Error] if this property is configured for single paths and an array is given @raise [Puppet::Error] if a path is not an absolute path @return [Array<String>] the given paths

   # File lib/puppet/parameter/path.rb
25 def validate_path(paths)
26   if paths.is_a?(Array) and ! self.class.arrays? then
27     fail _("%{name} only accepts a single path, not an array of paths") % { name: name }
28   end
29 
30   fail(_("%{name} must be a fully qualified path") % { name: name }) unless Array(paths).all? {|path| absolute_path?(path)}
31 
32   paths
33 end