aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMicah Anderson <micah@riseup.net>2009-11-23 11:54:04 -0500
committerMicah Anderson <micah@riseup.net>2009-11-23 11:54:04 -0500
commit3ff12051c8efabcdfb43b99810ff1c2ea22750a3 (patch)
tree5145331d85099abd1e01dabca1a474b9651184f6 /lib
parent8a389425075f54f8c10e2ff08c1aa07827d14622 (diff)
downloadpuppet-common-3ff12051c8efabcdfb43b99810ff1c2ea22750a3.tar.gz
puppet-common-3ff12051c8efabcdfb43b99810ff1c2ea22750a3.tar.bz2
move plugin directory to fit new 0.25.x style and update file paths accordingly
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/parser/functions/basename.rb22
-rw-r--r--lib/puppet/parser/functions/dirname.rb22
-rw-r--r--lib/puppet/parser/functions/gsub.rb21
-rw-r--r--lib/puppet/parser/functions/prefix_with.rb19
-rw-r--r--lib/puppet/parser/functions/re_escape.rb7
-rw-r--r--lib/puppet/parser/functions/split.rb23
6 files changed, 114 insertions, 0 deletions
diff --git a/lib/puppet/parser/functions/basename.rb b/lib/puppet/parser/functions/basename.rb
new file mode 100644
index 0000000..dc72537
--- /dev/null
+++ b/lib/puppet/parser/functions/basename.rb
@@ -0,0 +1,22 @@
+# This function has two modes of operation:
+#
+# basename(string) : string
+#
+# Returns the last component of the filename given as argument, which must be
+# formed using forward slashes ("/") regardless of the separator used on the
+# local file system.
+#
+# basename(string[]) : string[]
+#
+# Returns an array of strings with the basename of each item from the argument.
+#
+module Puppet::Parser::Functions
+ newfunction(:basename, :type => :rvalue) do |args|
+ if args[0].is_a?(Array)
+ args.collect do |a| File.basename(a) end
+ else
+ File.basename(args[0])
+ end
+ end
+end
+
diff --git a/lib/puppet/parser/functions/dirname.rb b/lib/puppet/parser/functions/dirname.rb
new file mode 100644
index 0000000..ea0d50b
--- /dev/null
+++ b/lib/puppet/parser/functions/dirname.rb
@@ -0,0 +1,22 @@
+# This function has two modes of operation:
+#
+# dirname(string) : string
+#
+# Returns all components of the filename given as argument except the last
+# one. The filename must be formed using forward slashes (``/..) regardless of
+# the separator used on the local file system.
+#
+# dirname(string[]) : string[]
+#
+# Returns an array of strings with the basename of each item from the argument.
+#
+module Puppet::Parser::Functions
+ newfunction(:dirname, :type => :rvalue) do |args|
+ if args[0].is_a?(Array)
+ args.collect do |a| File.dirname(a) end
+ else
+ File.dirname(args[0])
+ end
+ end
+end
+
diff --git a/lib/puppet/parser/functions/gsub.rb b/lib/puppet/parser/functions/gsub.rb
new file mode 100644
index 0000000..27e6192
--- /dev/null
+++ b/lib/puppet/parser/functions/gsub.rb
@@ -0,0 +1,21 @@
+#
+# A thin wrapper around the ruby gsub function.
+#
+# gsub($string, $pattern, $replacement)
+#
+# will replace all occurrences of $pattern in $string with $replacement.
+# $string can be either a single value or an array. In the latter case, each
+# element of the array will be processed in turn.
+#
+module Puppet::Parser::Functions
+ newfunction(:gsub, :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
+
diff --git a/lib/puppet/parser/functions/prefix_with.rb b/lib/puppet/parser/functions/prefix_with.rb
new file mode 100644
index 0000000..5a12986
--- /dev/null
+++ b/lib/puppet/parser/functions/prefix_with.rb
@@ -0,0 +1,19 @@
+# Prefixes arguments 2..n with first argument.
+#
+# prefix_with(string prefix, string[] arguments) : string[]
+#
+# Example:
+#
+# prefix_with("php-", [ "blah", "foo" ])
+#
+# will result in this array:
+#
+# [ "php-blah", "php-foo" ]
+#
+module Puppet::Parser::Functions
+ newfunction(:prefix_with, :type => :rvalue) do |args|
+ prefix = args.shift
+ args.collect {|v| "%s%s" % [prefix, v] }
+ end
+end
+
diff --git a/lib/puppet/parser/functions/re_escape.rb b/lib/puppet/parser/functions/re_escape.rb
new file mode 100644
index 0000000..7bee90a
--- /dev/null
+++ b/lib/puppet/parser/functions/re_escape.rb
@@ -0,0 +1,7 @@
+# apply ruby regexp escaping to a string
+module Puppet::Parser::Functions
+ newfunction(:re_escape, :type => :rvalue) do |args|
+ Regexp.escape(args[0])
+ end
+end
+
diff --git a/lib/puppet/parser/functions/split.rb b/lib/puppet/parser/functions/split.rb
new file mode 100644
index 0000000..bffecc1
--- /dev/null
+++ b/lib/puppet/parser/functions/split.rb
@@ -0,0 +1,23 @@
+# This function has two modes of operation:
+#
+# split($string, $delimiter) : $string
+#
+# Split the first argument on every $delimiter. $delimiter is interpreted as
+# Ruby regular expression.
+#
+# split($string[], $delimiter) : $string[][]
+#
+# Returns an array of split results with the result of applying split to each
+# item from the first argument.
+#
+# For long-term portability it is recommended to refrain from using Ruby's
+# extended RE features.
+module Puppet::Parser::Functions
+ newfunction(:split, :type => :rvalue) do |args|
+ if args[0].is_a?(Array)
+ args.collect do |a| a.split(/#{args[1]}/) end
+ else
+ args[0].split(/#{args[1]}/)
+ end
+ end
+end