Mercurial > repos > other > Puppet
comparison modules/stdlib/lib/puppet/parser/functions/camelcase.rb @ 272:c42fb28cff86
Update to a newer Python module
This also pulls in an EPEL module (which we don't use) and a newer
stdlib version.
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Fri, 03 Jan 2020 19:56:04 +0000 |
parents | addb0ea390a1 |
children | d9352a684e62 |
comparison
equal
deleted
inserted
replaced
271:c62728474654 | 272:c42fb28cff86 |
---|---|
1 # | 1 # |
2 # camelcase.rb | 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. | |
3 # | 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 DOC | |
9 ) do |arguments| | |
4 | 10 |
5 module Puppet::Parser::Functions | 11 raise(Puppet::ParseError, "camelcase(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? |
6 newfunction(:camelcase, :type => :rvalue, :doc => <<-EOS | |
7 Converts the case of a string or all strings in an array to camel case. | |
8 EOS | |
9 ) do |arguments| | |
10 | |
11 raise(Puppet::ParseError, "camelcase(): Wrong number of arguments " + | |
12 "given (#{arguments.size} for 1)") if arguments.size < 1 | |
13 | 12 |
14 value = arguments[0] | 13 value = arguments[0] |
15 klass = value.class | 14 klass = value.class |
16 | 15 |
17 unless [Array, String].include?(klass) | 16 unless [Array, String].include?(klass) |
18 raise(Puppet::ParseError, 'camelcase(): Requires either ' + | 17 raise(Puppet::ParseError, 'camelcase(): Requires either array or string to work with') |
19 'array or string to work with') | |
20 end | 18 end |
21 | 19 |
22 if value.is_a?(Array) | 20 result = if value.is_a?(Array) |
23 # Numbers in Puppet are often string-encoded which is troublesome ... | 21 # Numbers in Puppet are often string-encoded which is troublesome ... |
24 result = value.collect { |i| i.is_a?(String) ? i.split('_').map{|e| e.capitalize}.join : i } | 22 value.map { |i| i.is_a?(String) ? i.split('_').map { |e| e.capitalize }.join : i } |
25 else | 23 else |
26 result = value.split('_').map{|e| e.capitalize}.join | 24 value.split('_').map { |e| e.capitalize }.join |
27 end | 25 end |
28 | 26 |
29 return result | 27 return result |
30 end | 28 end |
31 end | 29 end |
32 | 30 |