aboutsummaryrefslogtreecommitdiff
path: root/plugins/puppet/parser/functions/substitute.rb
diff options
context:
space:
mode:
authorDavid Schmitt <david@schmitt.edv-bus.at>2008-08-25 16:45:29 +0200
committerDavid Schmitt <david@schmitt.edv-bus.at>2008-08-25 16:45:29 +0200
commit3a65dd853506db5d276e4162e6bd6920950fb21b (patch)
treef9923a81fab12a43bb0bfa99dcd3322e398c9898 /plugins/puppet/parser/functions/substitute.rb
parent0955f631b958effb60a85eb8f6e73797fd3d3aab (diff)
downloadpuppet-common-3a65dd853506db5d276e4162e6bd6920950fb21b.tar.gz
puppet-common-3a65dd853506db5d276e4162e6bd6920950fb21b.tar.bz2
improve documentation and function naming
Diffstat (limited to 'plugins/puppet/parser/functions/substitute.rb')
-rw-r--r--plugins/puppet/parser/functions/substitute.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/plugins/puppet/parser/functions/substitute.rb b/plugins/puppet/parser/functions/substitute.rb
new file mode 100644
index 0000000..4c97def
--- /dev/null
+++ b/plugins/puppet/parser/functions/substitute.rb
@@ -0,0 +1,20 @@
+# subsititute($string, $regex, $replacement) : $string
+# subsititute($string[], $regex, $replacement) : $string[]
+#
+# Replace all ocurrences of $regex in $string by $replacement.
+# $regex is interpreted as Ruby regular expression.
+#
+# For long-term portability it is recommended to refrain from using Ruby's
+# extended RE features.
+module Puppet::Parser::Functions
+ newfunction(:substitute, :type => :rvalue) do |args|
+ if args[0].is_a?(Array)
+ args[0].collect do |val|
+ val.gsub(/#{args[1]}/, args[2])
+ end
+ else
+ args[0].gsub(/#{args[1]}/, args[2])
+ end
+ end
+end
+