summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/functions
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/parser/functions')
-rw-r--r--lib/puppet/parser/functions/file.rb8
-rw-r--r--lib/puppet/parser/functions/fqdn_rand.rb2
-rw-r--r--lib/puppet/parser/functions/inline_template.rb3
-rw-r--r--lib/puppet/parser/functions/regsubst.rb49
-rw-r--r--lib/puppet/parser/functions/require.rb29
-rw-r--r--lib/puppet/parser/functions/sha1.rb3
-rw-r--r--lib/puppet/parser/functions/split.rb26
-rw-r--r--lib/puppet/parser/functions/sprintf.rb7
-rw-r--r--lib/puppet/parser/functions/template.rb7
-rw-r--r--lib/puppet/parser/functions/versioncmp.rb5
10 files changed, 82 insertions, 57 deletions
diff --git a/lib/puppet/parser/functions/file.rb b/lib/puppet/parser/functions/file.rb
index 47b3f96e0..f78823d3a 100644
--- a/lib/puppet/parser/functions/file.rb
+++ b/lib/puppet/parser/functions/file.rb
@@ -1,5 +1,8 @@
# Returns the contents of a file
-Puppet::Parser::Functions::newfunction(:file, :type => :rvalue,
+
+ Puppet::Parser::Functions::newfunction(
+ :file, :type => :rvalue,
+
:doc => "Return the contents of a file. Multiple files
can be passed, and the first file that exists will be read in.") do |vals|
ret = nil
@@ -15,7 +18,6 @@ Puppet::Parser::Functions::newfunction(:file, :type => :rvalue,
if ret
ret
else
- raise Puppet::ParseError, "Could not find any files from %s" %
- vals.join(", ")
+ raise Puppet::ParseError, "Could not find any files from %s" % vals.join(", ")
end
end
diff --git a/lib/puppet/parser/functions/fqdn_rand.rb b/lib/puppet/parser/functions/fqdn_rand.rb
index 9297539e3..27af2d7ca 100644
--- a/lib/puppet/parser/functions/fqdn_rand.rb
+++ b/lib/puppet/parser/functions/fqdn_rand.rb
@@ -1,6 +1,6 @@
Puppet::Parser::Functions::newfunction(:fqdn_rand, :type => :rvalue, :doc =>
"Generates random numbers based on the node's fqdn. The first argument
- sets the range. Additional (optional) arguments may be used to further
+ sets the range. Additional (optional) arguments may be used to further
distinguish the seed.") do |args|
require 'md5'
max = args.shift
diff --git a/lib/puppet/parser/functions/inline_template.rb b/lib/puppet/parser/functions/inline_template.rb
index b9547cac7..fde8006b4 100644
--- a/lib/puppet/parser/functions/inline_template.rb
+++ b/lib/puppet/parser/functions/inline_template.rb
@@ -14,8 +14,7 @@ Puppet::Parser::Functions::newfunction(:inline_template, :type => :rvalue, :doc
wrapper.result(string)
rescue => detail
raise Puppet::ParseError,
- "Failed to parse inline template: %s" %
- [detail]
+ "Failed to parse inline template: %s" % [detail]
end
end.join("")
end
diff --git a/lib/puppet/parser/functions/regsubst.rb b/lib/puppet/parser/functions/regsubst.rb
index d02680862..c47c1654e 100644
--- a/lib/puppet/parser/functions/regsubst.rb
+++ b/lib/puppet/parser/functions/regsubst.rb
@@ -1,7 +1,10 @@
module Puppet::Parser::Functions
- newfunction(:regsubst, :type => :rvalue,
- :doc => "
- Perform regexp replacement on a string or array of strings.
+
+ newfunction(
+ :regsubst, :type => :rvalue,
+
+ :doc => "
+ Perform regexp replacement on a string or array of strings.
- **Parameters** (in order):
@@ -20,10 +23,10 @@ module Puppet::Parser::Functions
:lang: Optional. How to handle multibyte characters. A single-character string with the following values:
- - **N** None
- - **E** EUC
- - **S** SJIS
- - **U** UTF-8
+ - **N** None
+ - **E** EUC
+ - **S** SJIS
+ - **U** UTF-8
- **Examples**
@@ -37,8 +40,11 @@ Put angle brackets around each octet in the node's IP address::
") \
do |args|
unless args.length.between?(3, 5)
- raise(Puppet::ParseError,
- "regsubst(): got #{args.length} arguments, expected 3 to 5")
+
+ raise(
+ Puppet::ParseError,
+
+ "regsubst(): got #{args.length} arguments, expected 3 to 5")
end
target, regexp, replacement, flags, lang = args
reflags = 0
@@ -48,8 +54,11 @@ Put angle brackets around each octet in the node's IP address::
elsif flags.respond_to?(:split)
flags = flags.split('')
else
- raise(Puppet::ParseError,
- "regsubst(): bad flags parameter #{flags.class}:`#{flags}'")
+
+ raise(
+ Puppet::ParseError,
+
+ "regsubst(): bad flags parameter #{flags.class}:`#{flags}'")
end
flags.each do |f|
case f
@@ -63,22 +72,28 @@ Put angle brackets around each octet in the node's IP address::
begin
re = Regexp.compile(regexp, reflags, lang)
rescue RegexpError, TypeError
- raise(Puppet::ParseError,
- "regsubst(): Bad regular expression `#{regexp}'")
+
+ raise(
+ Puppet::ParseError,
+
+ "regsubst(): Bad regular expression `#{regexp}'")
end
if target.respond_to?(operation)
# String parameter -> string result
result = target.send(operation, re, replacement)
elsif target.respond_to?(:collect) and
- target.respond_to?(:all?) and
- target.all? { |e| e.respond_to?(operation) }
+ target.respond_to?(:all?) and
+ target.all? { |e| e.respond_to?(operation) }
# Array parameter -> array result
result = target.collect { |e|
e.send(operation, re, replacement)
}
else
- raise(Puppet::ParseError,
- "regsubst(): bad target #{target.class}:`#{target}'")
+
+ raise(
+ Puppet::ParseError,
+
+ "regsubst(): bad target #{target.class}:`#{target}'")
end
return result
end
diff --git a/lib/puppet/parser/functions/require.rb b/lib/puppet/parser/functions/require.rb
index a46999f05..45b89c77a 100644
--- a/lib/puppet/parser/functions/require.rb
+++ b/lib/puppet/parser/functions/require.rb
@@ -1,5 +1,8 @@
# Requires the specified classes
-Puppet::Parser::Functions::newfunction(:require,
+
+ Puppet::Parser::Functions::newfunction(
+ :require,
+
:doc =>"Evaluate one or more classes, adding the required class as a dependency.
The relationship metaparameters work well for specifying relationships
@@ -9,18 +12,18 @@ relationships between classes. This function is a superset of the
class depends on the required class.
Warning: using require in place of include can lead to unwanted dependency cycles.
- For instance the following manifest, with 'require' instead of 'include'
- would produce a nasty dependence cycle, because notify imposes a before
- between File[/foo] and Service[foo]::
-
- class myservice {
- service { foo: ensure => running }
- }
-
- class otherstuff {
- include myservice
- file { '/foo': notify => Service[foo] }
- }
+ For instance the following manifest, with 'require' instead of 'include'
+ would produce a nasty dependence cycle, because notify imposes a before
+ between File[/foo] and Service[foo]::
+
+ class myservice {
+ service { foo: ensure => running }
+ }
+
+ class otherstuff {
+ include myservice
+ file { '/foo': notify => Service[foo] }
+ }
Note that this function only works with clients 0.25 and later, and it will
fail if used with earlier clients.
diff --git a/lib/puppet/parser/functions/sha1.rb b/lib/puppet/parser/functions/sha1.rb
index 09386a604..432825ee9 100644
--- a/lib/puppet/parser/functions/sha1.rb
+++ b/lib/puppet/parser/functions/sha1.rb
@@ -1,5 +1,4 @@
-Puppet::Parser::Functions::newfunction(:sha1, :type => :rvalue,
- :doc => "Returns a SHA1 hash value from a provided string.") do |args|
+Puppet::Parser::Functions::newfunction(:sha1, :type => :rvalue, :doc => "Returns a SHA1 hash value from a provided string.") do |args|
require 'sha1'
Digest::SHA1.hexdigest(args[0])
diff --git a/lib/puppet/parser/functions/split.rb b/lib/puppet/parser/functions/split.rb
index 36dba7e68..405a5bc9a 100644
--- a/lib/puppet/parser/functions/split.rb
+++ b/lib/puppet/parser/functions/split.rb
@@ -1,14 +1,17 @@
module Puppet::Parser::Functions
- newfunction(:split, :type => :rvalue,
- :doc => "\
+
+ newfunction(
+ :split, :type => :rvalue,
+
+ :doc => "\
Split a string variable into an array using the specified split regexp.
- Usage::
+ Usage::
- $string = 'v1.v2:v3.v4'
- $array_var1 = split($string, ':')
- $array_var2 = split($string, '[.]')
- $array_var3 = split($string, '[.:]')
+ $string = 'v1.v2:v3.v4'
+ $array_var1 = split($string, ':')
+ $array_var2 = split($string, '[.]')
+ $array_var3 = split($string, '[.:]')
$array_var1 now holds the result ['v1.v2', 'v3.v4'],
while $array_var2 holds ['v1', 'v2:v3', 'v4'], and
@@ -19,11 +22,10 @@ a regexp meta-character (.), and that needs protection. A simple
way to do that for a single character is to enclose it in square
brackets.") do |args|
- if args.length != 2
- raise Puppet::ParseError, ("split(): wrong number of arguments" +
- " (#{args.length}; must be 2)")
- end
+ if args.length != 2
+ raise Puppet::ParseError, ("split(): wrong number of arguments" + " (#{args.length}; must be 2)")
+ end
- return args[0].split(Regexp.compile(args[1]))
+ return args[0].split(Regexp.compile(args[1]))
end
end
diff --git a/lib/puppet/parser/functions/sprintf.rb b/lib/puppet/parser/functions/sprintf.rb
index d84b1866a..4a53a9736 100644
--- a/lib/puppet/parser/functions/sprintf.rb
+++ b/lib/puppet/parser/functions/sprintf.rb
@@ -1,8 +1,11 @@
module Puppet::Parser::Functions
- newfunction(:sprintf, :type => :rvalue,
+
+ newfunction(
+ :sprintf, :type => :rvalue,
+
:doc => "Perform printf-style formatting of text.
- The first parameter is format string describing how the rest of the parameters should be formatted. See the documentation for the ``Kernel::sprintf()`` function in Ruby for all the details.") do |args|
+ The first parameter is format string describing how the rest of the parameters should be formatted. See the documentation for the ``Kernel::sprintf()`` function in Ruby for all the details.") do |args|
if args.length < 1
raise Puppet::ParseError, 'sprintf() needs at least one argument'
end
diff --git a/lib/puppet/parser/functions/template.rb b/lib/puppet/parser/functions/template.rb
index 34524e388..35c54c66a 100644
--- a/lib/puppet/parser/functions/template.rb
+++ b/lib/puppet/parser/functions/template.rb
@@ -1,7 +1,7 @@
Puppet::Parser::Functions::newfunction(:template, :type => :rvalue, :doc =>
"Evaluate a template and return its value. See `the templating docs
- <http://docs.puppetlabs.com/guides/templating.html>`_ for more information.
- Note that if multiple templates are specified, their output is all
+ <http://docs.puppetlabs.com/guides/templating.html>`_ for more information.
+ Note that if multiple templates are specified, their output is all
concatenated and returned as the output of the function.") do |vals|
require 'erb'
@@ -16,8 +16,7 @@ Puppet::Parser::Functions::newfunction(:template, :type => :rvalue, :doc =>
wrapper.result
rescue => detail
raise Puppet::ParseError,
- "Failed to parse template %s: %s" %
- [file, detail]
+ "Failed to parse template %s: %s" % [file, detail]
end
end.join("")
end
diff --git a/lib/puppet/parser/functions/versioncmp.rb b/lib/puppet/parser/functions/versioncmp.rb
index 9435655a7..b8d39af96 100644
--- a/lib/puppet/parser/functions/versioncmp.rb
+++ b/lib/puppet/parser/functions/versioncmp.rb
@@ -1,6 +1,9 @@
require 'puppet/util/package'
-Puppet::Parser::Functions::newfunction(:versioncmp, :type => :rvalue,
+
+ Puppet::Parser::Functions::newfunction(
+ :versioncmp, :type => :rvalue,
+
:doc => "Compares two versions
Prototype::