|
@@ -0,0 +1,48 @@
|
|
|
+#
|
|
|
+#
|
|
|
+# Licensed to the Apache Software Foundation (ASF) under one
|
|
|
+# or more contributor license agreements. See the NOTICE file
|
|
|
+# distributed with this work for additional information
|
|
|
+# regarding copyright ownership. The ASF licenses this file
|
|
|
+# to you under the Apache License, Version 2.0 (the
|
|
|
+# "License"); you may not use this file except in compliance
|
|
|
+# with the License. You may obtain a copy of the License at
|
|
|
+#
|
|
|
+# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
+#
|
|
|
+# Unless required by applicable law or agreed to in writing,
|
|
|
+# software distributed under the License is distributed on an
|
|
|
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
+# KIND, either express or implied. See the License for the
|
|
|
+# specific language governing permissions and limitations
|
|
|
+# under the License.
|
|
|
+#
|
|
|
+#
|
|
|
+
|
|
|
+module Puppet::Parser::Functions
|
|
|
+ newfunction(:hdp_to_lowercase, :type => :rvalue, :doc => <<-EOS
|
|
|
+Converts the case of a string or all strings in an array to lower case.
|
|
|
+ EOS
|
|
|
+ ) do |arguments|
|
|
|
+
|
|
|
+ raise(Puppet::ParseError, "downcase(): Wrong number of arguments " +
|
|
|
+ "given (#{arguments.size} for 1)") if arguments.size < 1
|
|
|
+
|
|
|
+ value = arguments[0]
|
|
|
+ klass = value.class
|
|
|
+
|
|
|
+ unless [Array, String].include?(klass)
|
|
|
+ raise(Puppet::ParseError, 'downcase(): Requires either ' +
|
|
|
+ 'array or string to work with')
|
|
|
+ end
|
|
|
+
|
|
|
+ if value.is_a?(Array)
|
|
|
+ # Numbers in Puppet are often string-encoded which is troublesome ...
|
|
|
+ result = value.collect { |i| i.is_a?(String) ? i.downcase : i }
|
|
|
+ else
|
|
|
+ result = value.downcase
|
|
|
+ end
|
|
|
+
|
|
|
+ return result
|
|
|
+ end
|
|
|
+end
|