Skip to content

Commit 19313b4

Browse files
committed
(puppetlabs#3) Apply missing documentation to more functions.
1 parent f9634b7 commit 19313b4

24 files changed

+235
-13
lines changed

lib/puppet/parser/functions/num2bool.rb

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
module Puppet::Parser::Functions
88
newfunction(:num2bool, :type => :rvalue, :doc => <<-EOS
9+
This function converts a number into a true boolean. Zero becomes false. Numbers
10+
higher then 0 become true.
911
EOS
1012
) do |arguments|
1113

lib/puppet/parser/functions/prefix.rb

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:prefix, :type => :rvalue, :doc => <<-EOS
7+
This function applies a prefix to all elements in an array.
8+
9+
*Examles:*
10+
11+
prefix(['a','b','c'], 'p')
12+
13+
Will return: ['pa','pb','pc']
714
EOS
815
) do |arguments|
916

lib/puppet/parser/functions/range.rb

+12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@
66

77
module Puppet::Parser::Functions
88
newfunction(:range, :type => :rvalue, :doc => <<-EOS
9+
When given range in the form of (start, stop) it will extrapolate a range as
10+
an array.
11+
12+
*Examples:*
13+
14+
range("0", "9")
15+
16+
Will return: [0,1,2,3,4,5,6,7,8,9]
17+
18+
range("a", "c")
19+
20+
Will return: ["a","b","c"]
921
EOS
1022
) do |arguments|
1123

lib/puppet/parser/functions/reverse.rb

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:reverse, :type => :rvalue, :doc => <<-EOS
7+
Reverses the order of a string or array.
78
EOS
89
) do |arguments|
910

lib/puppet/parser/functions/rstrip.rb

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:rstrip, :type => :rvalue, :doc => <<-EOS
7+
Strips leading spaces to the right of the string.
78
EOS
89
) do |arguments|
910

lib/puppet/parser/functions/shuffle.rb

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:shuffle, :type => :rvalue, :doc => <<-EOS
7+
Randomizes the order of a string or array elements.
78
EOS
89
) do |arguments|
910

lib/puppet/parser/functions/size.rb

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
module Puppet::Parser::Functions
88
newfunction(:size, :type => :rvalue, :doc => <<-EOS
9+
Returns the number of elements in a string or array.
910
EOS
1011
) do |arguments|
1112

lib/puppet/parser/functions/sort.rb

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:sort, :type => :rvalue, :doc => <<-EOS
7+
Sorts strings and arrays lexically.
78
EOS
89
) do |arguments|
910

lib/puppet/parser/functions/squeeze.rb

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:squeeze, :type => :rvalue, :doc => <<-EOS
7+
Returns a new string where runs of the same character that occur in this set are replaced by a single character.
78
EOS
89
) do |arguments|
910

lib/puppet/parser/functions/str2bool.rb

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:str2bool, :type => :rvalue, :doc => <<-EOS
7+
This converts a string to a boolean. This attempt to convert strings that
8+
contain things like: y, 1, t, true to 'true' and strings that contain things
9+
like: 0, f, n, false, no to 'false'.
710
EOS
811
) do |arguments|
912

lib/puppet/parser/functions/strftime.rb

+63
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,69 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:strftime, :type => :rvalue, :doc => <<-EOS
7+
This function returns formatted time.
8+
9+
*Examples:*
10+
11+
To return the time since epoch:
12+
13+
strftime("%s")
14+
15+
To return the date:
16+
17+
strftime("%Y-%m-%d")
18+
19+
*Format meaning:*
20+
21+
%a - The abbreviated weekday name (``Sun'')
22+
%A - The full weekday name (``Sunday'')
23+
%b - The abbreviated month name (``Jan'')
24+
%B - The full month name (``January'')
25+
%c - The preferred local date and time representation
26+
%C - Century (20 in 2009)
27+
%d - Day of the month (01..31)
28+
%D - Date (%m/%d/%y)
29+
%e - Day of the month, blank-padded ( 1..31)
30+
%F - Equivalent to %Y-%m-%d (the ISO 8601 date format)
31+
%h - Equivalent to %b
32+
%H - Hour of the day, 24-hour clock (00..23)
33+
%I - Hour of the day, 12-hour clock (01..12)
34+
%j - Day of the year (001..366)
35+
%k - hour, 24-hour clock, blank-padded ( 0..23)
36+
%l - hour, 12-hour clock, blank-padded ( 0..12)
37+
%L - Millisecond of the second (000..999)
38+
%m - Month of the year (01..12)
39+
%M - Minute of the hour (00..59)
40+
%n - Newline (\n)
41+
%N - Fractional seconds digits, default is 9 digits (nanosecond)
42+
%3N millisecond (3 digits)
43+
%6N microsecond (6 digits)
44+
%9N nanosecond (9 digits)
45+
%p - Meridian indicator (``AM'' or ``PM'')
46+
%P - Meridian indicator (``am'' or ``pm'')
47+
%r - time, 12-hour (same as %I:%M:%S %p)
48+
%R - time, 24-hour (%H:%M)
49+
%s - Number of seconds since 1970-01-01 00:00:00 UTC.
50+
%S - Second of the minute (00..60)
51+
%t - Tab character (\t)
52+
%T - time, 24-hour (%H:%M:%S)
53+
%u - Day of the week as a decimal, Monday being 1. (1..7)
54+
%U - Week number of the current year,
55+
starting with the first Sunday as the first
56+
day of the first week (00..53)
57+
%v - VMS date (%e-%b-%Y)
58+
%V - Week number of year according to ISO 8601 (01..53)
59+
%W - Week number of the current year,
60+
starting with the first Monday as the first
61+
day of the first week (00..53)
62+
%w - Day of the week (Sunday is 0, 0..6)
63+
%x - Preferred representation for the date alone, no time
64+
%X - Preferred representation for the time alone, no date
65+
%y - Year without a century (00..99)
66+
%Y - Year with century
67+
%z - Time zone as hour offset from UTC (e.g. +0900)
68+
%Z - Time zone name
69+
%% - Literal ``%'' character
770
EOS
871
) do |arguments|
972

lib/puppet/parser/functions/strip.rb

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:strip, :type => :rvalue, :doc => <<-EOS
7+
This function removes leading and trailing whitespace from a string or from
8+
every string inside an array.
9+
10+
*Examples:*
11+
12+
strip(" aaa ")
13+
14+
Would result in: "aaa"
715
EOS
816
) do |arguments|
917

lib/puppet/parser/functions/swapcase.rb

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:swapcase, :type => :rvalue, :doc => <<-EOS
7+
This function will swap the existing case of a string.
8+
9+
*Examples:*
10+
11+
swapcase("aBcD")
12+
13+
Would result in: "AbCd"
714
EOS
815
) do |arguments|
916

lib/puppet/parser/functions/time.rb

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:time, :type => :rvalue, :doc => <<-EOS
7+
This function will return the current time since epoch as an integer.
8+
9+
*Examples:*
10+
11+
time()
12+
13+
Will return something like: 1311972653
714
EOS
815
) do |arguments|
916

lib/puppet/parser/functions/type.rb

+17-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:type, :type => :rvalue, :doc => <<-EOS
7+
Returns the type when passed a variable. Type can be one of:
8+
9+
* string
10+
* array
11+
* hash
12+
* float
13+
* integer
714
EOS
815
) do |arguments|
916

@@ -22,11 +29,19 @@ module Puppet::Parser::Functions
2229

2330
# We note that Integer is the parent to Bignum and Fixnum ...
2431
result = case klass
25-
when /^(?:Big|Fix)num$/ then 'Integer'
32+
when /^(?:Big|Fix)num$/ then 'integer'
2633
else klass
2734
end
2835

29-
return result
36+
if result == "String" then
37+
if value == value.to_i.to_s then
38+
result = "Integer"
39+
elsif value == value.to_f.to_s then
40+
result = "Float"
41+
end
42+
end
43+
44+
return result.downcase
3045
end
3146
end
3247

lib/puppet/parser/functions/unique.rb

+17
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:unique, :type => :rvalue, :doc => <<-EOS
7+
This function will remove duplicates from strings and arrays.
8+
9+
*Examples:*
10+
11+
unique("aabbcc")
12+
13+
Will return:
14+
15+
abc
16+
17+
You can also use this with arrays:
18+
19+
unique(["a","a","b","b","c","c"])
20+
21+
This returns:
22+
23+
["a","b","c"]
724
EOS
825
) do |arguments|
926

lib/puppet/parser/functions/upcase.rb

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:upcase, :type => :rvalue, :doc => <<-EOS
7+
Converts a string or an array of strings to uppercase.
8+
9+
*Examples:*
10+
11+
upcase("abcd")
12+
13+
Will return:
14+
15+
ASDF
716
EOS
817
) do |arguments|
918

lib/puppet/parser/functions/validate_resource.rb

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:validate_resource, :type => :statement, :doc => <<-EOS
7+
This function when placed at the beginning of a class, will go looking for a
8+
valid kwalify schema by replacing the extension of the file with '.schema'.
9+
10+
It will then validate the arguments passed to the function using that kwalify
11+
schema.
712
EOS
813
) do |arguments|
914

lib/puppet/parser/functions/values.rb

+14
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:values, :type => :rvalue, :doc => <<-EOS
7+
When given a hash this function will return the values of that hash.
8+
9+
*Examples:*
10+
11+
$hash = {
12+
'a' => 1,
13+
'b' => 2,
14+
'c' => 3,
15+
}
16+
values($hash)
17+
18+
This example would return:
19+
20+
[1,2,3]
721
EOS
822
) do |arguments|
923

lib/puppet/parser/functions/values_at.rb

+22-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,30 @@
22
# values_at.rb
33
#
44

5-
# TODO(Krzysztof Wilczynski): Support for hashes would be nice too ...
6-
# TODO(Krzysztof Wilczynski): We probably need to approach numeric values differently ...
7-
85
module Puppet::Parser::Functions
96
newfunction(:values_at, :type => :rvalue, :doc => <<-EOS
7+
Finds value inside an array based on location.
8+
9+
The first argument is the array you want to analyze, and the second element can
10+
be a combination of:
11+
12+
* A single numeric index
13+
* A range in the form of 'start-stop' (eg. 4-9)
14+
* An array combining the above
15+
16+
*Examples*:
17+
18+
values_at(['a','b','c'], 2)
19+
20+
Would return ['c'].
21+
22+
values_at(['a','b','c'], ["0-1"])
23+
24+
Would return ['a','b'].
25+
26+
values_at(['a','b','c','d','e'], [0, "2-3"])
27+
28+
Would return ['a','c','d'].
1029
EOS
1130
) do |arguments|
1231

lib/puppet/parser/functions/zip.rb

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:zip, :type => :rvalue, :doc => <<-EOS
7+
Takes one element from first array and merges corresponding elements from second array. This generates a sequence of n-element arrays, where n is one more than the count of arguments.
8+
9+
*Example:*
10+
11+
zip(['1','2','3'],['4','5','6'])
12+
13+
Would result in:
14+
15+
["1", "4"], ["2", "5"], ["3", "6"]
716
EOS
817
) do |arguments|
918

0 commit comments

Comments
 (0)