source: other-projects/hathitrust/vagrant-hadoop-cluster/trunk/modules/stdlib/lib/puppet/parser/functions/uriescape.rb@ 30903

Last change on this file since 30903 was 30903, checked in by davidb, 8 years ago

Vagrant provisioning files for a 4-node Hadoop cluster. See README.txt for more details

File size: 874 bytes
Line 
1#
2# uriescape.rb
3#
4require 'uri'
5
6module Puppet::Parser::Functions
7 newfunction(:uriescape, :type => :rvalue, :doc => <<-EOS
8 Urlencodes a string or array of strings.
9 Requires either a single string or an array as an input.
10 EOS
11 ) do |arguments|
12
13 raise(Puppet::ParseError, "uriescape(): Wrong number of arguments " +
14 "given (#{arguments.size} for 1)") if arguments.size < 1
15
16 value = arguments[0]
17
18 unless value.is_a?(Array) || value.is_a?(String)
19 raise(Puppet::ParseError, 'uriescape(): Requires either ' +
20 'array or string to work with')
21 end
22
23 if value.is_a?(Array)
24 # Numbers in Puppet are often string-encoded which is troublesome ...
25 result = value.collect { |i| i.is_a?(String) ? URI.escape(i) : i }
26 else
27 result = URI.escape(value)
28 end
29
30 return result
31 end
32end
33
34# vim: set ts=2 sw=2 et :
Note: See TracBrowser for help on using the repository browser.