Mercurial > repos > other > Puppet
comparison modules/stdlib/lib/puppet/parser/functions/downcase.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 # downcase.rb | 2 # downcase.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(:downcase, :type => :rvalue, :doc => <<-DOC | |
7 Converts the case of a string or all strings in an array to lower case. | |
8 DOC | |
9 ) do |arguments| | |
4 | 10 |
5 module Puppet::Parser::Functions | 11 raise(Puppet::ParseError, "downcase(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? |
6 newfunction(:downcase, :type => :rvalue, :doc => <<-EOS | |
7 Converts the case of a string or all strings in an array to lower case. | |
8 EOS | |
9 ) do |arguments| | |
10 | |
11 raise(Puppet::ParseError, "downcase(): 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 | 14 |
16 unless value.is_a?(Array) || value.is_a?(String) | 15 unless value.is_a?(Array) || value.is_a?(String) |
17 raise(Puppet::ParseError, 'downcase(): Requires either ' + | 16 raise(Puppet::ParseError, 'downcase(): Requires either array or string to work with') |
18 'array or string to work with') | |
19 end | 17 end |
20 | 18 |
21 if value.is_a?(Array) | 19 result = if value.is_a?(Array) |
22 # Numbers in Puppet are often string-encoded which is troublesome ... | 20 # Numbers in Puppet are often string-encoded which is troublesome ... |
23 result = value.collect { |i| i.is_a?(String) ? i.downcase : i } | 21 value.map { |i| i.is_a?(String) ? i.downcase : i } |
24 else | 22 else |
25 result = value.downcase | 23 value.downcase |
26 end | 24 end |
27 | 25 |
28 return result | 26 return result |
29 end | 27 end |
30 end | 28 end |
31 | 29 |