(#3) Provide documentation for remaining functions.
This commit is contained in:
parent
19313b43ea
commit
a1cae426f1
24 changed files with 83 additions and 2 deletions
|
@ -7,11 +7,18 @@
|
|||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:delete, :type => :rvalue, :doc => <<-EOS
|
||||
Deletes a selected element from an array.
|
||||
|
||||
*Examples:*
|
||||
|
||||
delete(['a','b','c'], 'b')
|
||||
|
||||
Would return: ['a','c']
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
if (arguments.size != 2) then
|
||||
raise(Puppet::ParseError, "is_valid_netmask(): Wrong number of arguments "+
|
||||
raise(Puppet::ParseError, "delete(): Wrong number of arguments "+
|
||||
"given #{arguments.size} for 2")
|
||||
end
|
||||
|
||||
|
|
|
@ -4,6 +4,13 @@
|
|||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:delete_at, :type => :rvalue, :doc => <<-EOS
|
||||
Deletes a determined indexed value from an array.
|
||||
|
||||
*Examples:*
|
||||
|
||||
delete_at(['a','b','c'], 1)
|
||||
|
||||
Would return: ['a','c']
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:downcase, :type => :rvalue, :doc => <<-EOS
|
||||
Converts the case of a string or all strings in an array to lower case.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:empty, :type => :rvalue, :doc => <<-EOS
|
||||
Returns true if the variable is empty.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
|
|
|
@ -4,6 +4,14 @@
|
|||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:flatten, :type => :rvalue, :doc => <<-EOS
|
||||
This function flattens any deeply nested arrays and returns a single flat array
|
||||
as a result.
|
||||
|
||||
*Examples:*
|
||||
|
||||
flatten(['a', ['b', ['c']]])
|
||||
|
||||
Would return: ['a','b','c']
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
|
|
|
@ -4,6 +4,16 @@
|
|||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:grep, :type => :rvalue, :doc => <<-EOS
|
||||
This function searches through an array and returns any elements that match
|
||||
the provided regular expression.
|
||||
|
||||
*Examples:*
|
||||
|
||||
grep(['aaa','bbb','ccc','aaaddd'], 'aaa')
|
||||
|
||||
Would return:
|
||||
|
||||
['aaa','aaaddd']
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
|
|
|
@ -4,6 +4,13 @@
|
|||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:hash, :type => :rvalue, :doc => <<-EOS
|
||||
This function converts and array into a hash.
|
||||
|
||||
*Examples:*
|
||||
|
||||
hash(['a',1,'b',2,'c',3])
|
||||
|
||||
Would return: {'a'=>1,'b'=>2,'c'=>3}
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:is_array, :type => :rvalue, :doc => <<-EOS
|
||||
Returns true if the variable passed to this function is an array.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:is_float, :type => :rvalue, :doc => <<-EOS
|
||||
Returns true if the variable passed to this function is a float.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:is_hash, :type => :rvalue, :doc => <<-EOS
|
||||
Returns true if the variable passed to this function is a hash.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:is_integer, :type => :rvalue, :doc => <<-EOS
|
||||
Returns true if the variable returned to this string is an integer.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:is_numeric, :type => :rvalue, :doc => <<-EOS
|
||||
Returns true if the variable passed to this function is a number.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:is_string, :type => :rvalue, :doc => <<-EOS
|
||||
Returns true if the variable passed to this function is a string.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:is_valid_domain_name, :type => :rvalue, :doc => <<-EOS
|
||||
Returns true if the string passed to this function is a valid IP address. Support for IPv4 and IPv6 address types is included.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:is_valid_ip_address, :type => :rvalue, :doc => <<-EOS
|
||||
Returns true if the string passed to this function is a valid IP address.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:is_valid_mac_address, :type => :rvalue, :doc => <<-EOS
|
||||
Returns true if the string passed to this function is a valid mac address.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
|
|
|
@ -4,6 +4,13 @@
|
|||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:join, :type => :rvalue, :doc => <<-EOS
|
||||
This function joins an array into a string using a seperator.
|
||||
|
||||
*Examples:*
|
||||
|
||||
join(['a','b','c'], ",")
|
||||
|
||||
Would result in: "a,b,c"
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:keys, :type => :rvalue, :doc => <<-EOS
|
||||
Returns the keys of a hash as an array.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:load_json, :type => :rvalue, :doc => <<-EOS
|
||||
This function accepts JSON as a string and converts into the correct Puppet
|
||||
structure.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:load_yaml, :type => :rvalue, :doc => <<-EOS
|
||||
This function accepts YAML as a string and converts it into the correct
|
||||
Puppet structure.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:lstrip, :type => :rvalue, :doc => <<-EOS
|
||||
Strips leading spaces to the left of a string.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
|
|
|
@ -7,6 +7,17 @@
|
|||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:member, :type => :rvalue, :doc => <<-EOS
|
||||
This function determines if a variable is a member of an array.
|
||||
|
||||
*Examples:*
|
||||
|
||||
member(['a','b'], 'b')
|
||||
|
||||
Would return: true
|
||||
|
||||
member(['a','b'], 'c')
|
||||
|
||||
Would return: false
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ Returns the type when passed a variable. Type can be one of:
|
|||
* hash
|
||||
* float
|
||||
* integer
|
||||
* boolean
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
|
@ -21,7 +22,7 @@ Returns the type when passed a variable. Type can be one of:
|
|||
|
||||
klass = value.class
|
||||
|
||||
if not [Array, Bignum, Fixnum, Float, Hash, String].include?(klass)
|
||||
if not [TrueClass, FalseClass, Array, Bignum, Fixnum, Float, Hash, String].include?(klass)
|
||||
raise(Puppet::ParseError, 'type(): Unknown type')
|
||||
end
|
||||
|
||||
|
@ -30,6 +31,7 @@ Returns the type when passed a variable. Type can be one of:
|
|||
# We note that Integer is the parent to Bignum and Fixnum ...
|
||||
result = case klass
|
||||
when /^(?:Big|Fix)num$/ then 'integer'
|
||||
when /^(?:True|False)Class$/ then 'boolean'
|
||||
else klass
|
||||
end
|
||||
|
||||
|
|
|
@ -43,4 +43,9 @@ describe "the type function" do
|
|||
result.should(eq('float'))
|
||||
end
|
||||
|
||||
it "should return boolean when given a boolean" do
|
||||
result = @scope.function_type([true])
|
||||
result.should(eq('boolean'))
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue