annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
37
addb0ea390a1 Update Puppet "stdlib" module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 #
addb0ea390a1 Update Puppet "stdlib" module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 # camelcase.rb
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 37
diff changeset
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.
37
addb0ea390a1 Update Puppet "stdlib" module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 #
addb0ea390a1 Update Puppet "stdlib" module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 module Puppet::Parser::Functions
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 37
diff changeset
6 newfunction(:camelcase, :type => :rvalue, :doc => <<-DOC
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 37
diff changeset
7 Converts the case of a string or all strings in an array to camel case.
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 37
diff changeset
8 DOC
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 37
diff changeset
9 ) do |arguments|
37
addb0ea390a1 Update Puppet "stdlib" module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 37
diff changeset
11 raise(Puppet::ParseError, "camelcase(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
37
addb0ea390a1 Update Puppet "stdlib" module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12
addb0ea390a1 Update Puppet "stdlib" module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 value = arguments[0]
addb0ea390a1 Update Puppet "stdlib" module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 klass = value.class
addb0ea390a1 Update Puppet "stdlib" module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15
addb0ea390a1 Update Puppet "stdlib" module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 unless [Array, String].include?(klass)
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 37
diff changeset
17 raise(Puppet::ParseError, 'camelcase(): Requires either array or string to work with')
37
addb0ea390a1 Update Puppet "stdlib" module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 end
addb0ea390a1 Update Puppet "stdlib" module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 37
diff changeset
20 result = if value.is_a?(Array)
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 37
diff changeset
21 # Numbers in Puppet are often string-encoded which is troublesome ...
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 37
diff changeset
22 value.map { |i| i.is_a?(String) ? i.split('_').map { |e| e.capitalize }.join : i }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 37
diff changeset
23 else
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 37
diff changeset
24 value.split('_').map { |e| e.capitalize }.join
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 37
diff changeset
25 end
37
addb0ea390a1 Update Puppet "stdlib" module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26
addb0ea390a1 Update Puppet "stdlib" module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 return result
addb0ea390a1 Update Puppet "stdlib" module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 end
addb0ea390a1 Update Puppet "stdlib" module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 end
addb0ea390a1 Update Puppet "stdlib" module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30
addb0ea390a1 Update Puppet "stdlib" module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 # vim: set ts=2 sw=2 et :