Skip to content

Commit a1cae42

Browse files
committed
(puppetlabs#3) Provide documentation for remaining functions.
1 parent 19313b4 commit a1cae42

24 files changed

+83
-2
lines changed

lib/puppet/parser/functions/delete.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@
77

88
module Puppet::Parser::Functions
99
newfunction(:delete, :type => :rvalue, :doc => <<-EOS
10+
Deletes a selected element from an array.
11+
12+
*Examples:*
13+
14+
delete(['a','b','c'], 'b')
15+
16+
Would return: ['a','c']
1017
EOS
1118
) do |arguments|
1219

1320
if (arguments.size != 2) then
14-
raise(Puppet::ParseError, "is_valid_netmask(): Wrong number of arguments "+
21+
raise(Puppet::ParseError, "delete(): Wrong number of arguments "+
1522
"given #{arguments.size} for 2")
1623
end
1724

lib/puppet/parser/functions/delete_at.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:delete_at, :type => :rvalue, :doc => <<-EOS
7+
Deletes a determined indexed value from an array.
8+
9+
*Examples:*
10+
11+
delete_at(['a','b','c'], 1)
12+
13+
Would return: ['a','c']
714
EOS
815
) do |arguments|
916

lib/puppet/parser/functions/downcase.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:downcase, :type => :rvalue, :doc => <<-EOS
7+
Converts the case of a string or all strings in an array to lower case.
78
EOS
89
) do |arguments|
910

lib/puppet/parser/functions/empty.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:empty, :type => :rvalue, :doc => <<-EOS
7+
Returns true if the variable is empty.
78
EOS
89
) do |arguments|
910

lib/puppet/parser/functions/flatten.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:flatten, :type => :rvalue, :doc => <<-EOS
7+
This function flattens any deeply nested arrays and returns a single flat array
8+
as a result.
9+
10+
*Examples:*
11+
12+
flatten(['a', ['b', ['c']]])
13+
14+
Would return: ['a','b','c']
715
EOS
816
) do |arguments|
917

lib/puppet/parser/functions/grep.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:grep, :type => :rvalue, :doc => <<-EOS
7+
This function searches through an array and returns any elements that match
8+
the provided regular expression.
9+
10+
*Examples:*
11+
12+
grep(['aaa','bbb','ccc','aaaddd'], 'aaa')
13+
14+
Would return:
15+
16+
['aaa','aaaddd']
717
EOS
818
) do |arguments|
919

lib/puppet/parser/functions/hash.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:hash, :type => :rvalue, :doc => <<-EOS
7+
This function converts and array into a hash.
8+
9+
*Examples:*
10+
11+
hash(['a',1,'b',2,'c',3])
12+
13+
Would return: {'a'=>1,'b'=>2,'c'=>3}
714
EOS
815
) do |arguments|
916

lib/puppet/parser/functions/is_array.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:is_array, :type => :rvalue, :doc => <<-EOS
7+
Returns true if the variable passed to this function is an array.
78
EOS
89
) do |arguments|
910

lib/puppet/parser/functions/is_float.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:is_float, :type => :rvalue, :doc => <<-EOS
7+
Returns true if the variable passed to this function is a float.
78
EOS
89
) do |arguments|
910

lib/puppet/parser/functions/is_hash.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:is_hash, :type => :rvalue, :doc => <<-EOS
7+
Returns true if the variable passed to this function is a hash.
78
EOS
89
) do |arguments|
910

lib/puppet/parser/functions/is_integer.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:is_integer, :type => :rvalue, :doc => <<-EOS
7+
Returns true if the variable returned to this string is an integer.
78
EOS
89
) do |arguments|
910

lib/puppet/parser/functions/is_numeric.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:is_numeric, :type => :rvalue, :doc => <<-EOS
7+
Returns true if the variable passed to this function is a number.
78
EOS
89
) do |arguments|
910

lib/puppet/parser/functions/is_string.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:is_string, :type => :rvalue, :doc => <<-EOS
7+
Returns true if the variable passed to this function is a string.
78
EOS
89
) do |arguments|
910

lib/puppet/parser/functions/is_valid_domain_name.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:is_valid_domain_name, :type => :rvalue, :doc => <<-EOS
7+
Returns true if the string passed to this function is a valid IP address. Support for IPv4 and IPv6 address types is included.
78
EOS
89
) do |arguments|
910

lib/puppet/parser/functions/is_valid_ip_address.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:is_valid_ip_address, :type => :rvalue, :doc => <<-EOS
7+
Returns true if the string passed to this function is a valid IP address.
78
EOS
89
) do |arguments|
910

lib/puppet/parser/functions/is_valid_mac_address.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:is_valid_mac_address, :type => :rvalue, :doc => <<-EOS
7+
Returns true if the string passed to this function is a valid mac address.
78
EOS
89
) do |arguments|
910

lib/puppet/parser/functions/join.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:join, :type => :rvalue, :doc => <<-EOS
7+
This function joins an array into a string using a seperator.
8+
9+
*Examples:*
10+
11+
join(['a','b','c'], ",")
12+
13+
Would result in: "a,b,c"
714
EOS
815
) do |arguments|
916

lib/puppet/parser/functions/keys.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:keys, :type => :rvalue, :doc => <<-EOS
7+
Returns the keys of a hash as an array.
78
EOS
89
) do |arguments|
910

lib/puppet/parser/functions/load_json.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:load_json, :type => :rvalue, :doc => <<-EOS
7+
This function accepts JSON as a string and converts into the correct Puppet
8+
structure.
79
EOS
810
) do |arguments|
911

lib/puppet/parser/functions/load_yaml.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
module Puppet::Parser::Functions
66
newfunction(:load_yaml, :type => :rvalue, :doc => <<-EOS
7+
This function accepts YAML as a string and converts it into the correct
8+
Puppet structure.
79
EOS
810
) do |arguments|
911

lib/puppet/parser/functions/lstrip.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

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

lib/puppet/parser/functions/member.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77

88
module Puppet::Parser::Functions
99
newfunction(:member, :type => :rvalue, :doc => <<-EOS
10+
This function determines if a variable is a member of an array.
11+
12+
*Examples:*
13+
14+
member(['a','b'], 'b')
15+
16+
Would return: true
17+
18+
member(['a','b'], 'c')
19+
20+
Would return: false
1021
EOS
1122
) do |arguments|
1223

lib/puppet/parser/functions/type.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module Puppet::Parser::Functions
1111
* hash
1212
* float
1313
* integer
14+
* boolean
1415
EOS
1516
) do |arguments|
1617

@@ -21,7 +22,7 @@ module Puppet::Parser::Functions
2122

2223
klass = value.class
2324

24-
if not [Array, Bignum, Fixnum, Float, Hash, String].include?(klass)
25+
if not [TrueClass, FalseClass, Array, Bignum, Fixnum, Float, Hash, String].include?(klass)
2526
raise(Puppet::ParseError, 'type(): Unknown type')
2627
end
2728

@@ -30,6 +31,7 @@ module Puppet::Parser::Functions
3031
# We note that Integer is the parent to Bignum and Fixnum ...
3132
result = case klass
3233
when /^(?:Big|Fix)num$/ then 'integer'
34+
when /^(?:True|False)Class$/ then 'boolean'
3335
else klass
3436
end
3537

spec/unit/parser/functions/type_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,9 @@
4343
result.should(eq('float'))
4444
end
4545

46+
it "should return boolean when given a boolean" do
47+
result = @scope.function_type([true])
48+
result.should(eq('boolean'))
49+
end
50+
4651
end

0 commit comments

Comments
 (0)