Suggest different variables to use if we want to tunnel both v4 and v6
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / camelcase.rb
1 #
2 #  camelcase.rb
3 #  Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085.
4 #
5 module Puppet::Parser::Functions
6   newfunction(:camelcase, :type => :rvalue, :doc => <<-DOC
7     Converts the case of a string or all strings in an array to camel case.
8
9     Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core
10     will be used instead of this function.
11   DOC
12              ) do |arguments|
13
14     raise(Puppet::ParseError, "camelcase(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
15
16     value = arguments[0]
17     klass = value.class
18
19     unless [Array, String].include?(klass)
20       raise(Puppet::ParseError, 'camelcase(): Requires either array or string to work with')
21     end
22
23     result = if value.is_a?(Array)
24                # Numbers in Puppet are often string-encoded which is troublesome ...
25                value.map { |i| i.is_a?(String) ? i.split('_').map { |e| e.capitalize }.join : i }
26              else
27                value.split('_').map { |e| e.capitalize }.join
28              end
29
30     return result
31   end
32 end
33
34 # vim: set ts=2 sw=2 et :