]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
(#3) Provide documentation for remaining functions.
authorKen Barber <ken@bob.sh>
Fri, 29 Jul 2011 22:09:30 +0000 (23:09 +0100)
committerKen Barber <ken@bob.sh>
Fri, 29 Jul 2011 22:09:30 +0000 (23:09 +0100)
24 files changed:
lib/puppet/parser/functions/delete.rb
lib/puppet/parser/functions/delete_at.rb
lib/puppet/parser/functions/downcase.rb
lib/puppet/parser/functions/empty.rb
lib/puppet/parser/functions/flatten.rb
lib/puppet/parser/functions/grep.rb
lib/puppet/parser/functions/hash.rb
lib/puppet/parser/functions/is_array.rb
lib/puppet/parser/functions/is_float.rb
lib/puppet/parser/functions/is_hash.rb
lib/puppet/parser/functions/is_integer.rb
lib/puppet/parser/functions/is_numeric.rb
lib/puppet/parser/functions/is_string.rb
lib/puppet/parser/functions/is_valid_domain_name.rb
lib/puppet/parser/functions/is_valid_ip_address.rb
lib/puppet/parser/functions/is_valid_mac_address.rb
lib/puppet/parser/functions/join.rb
lib/puppet/parser/functions/keys.rb
lib/puppet/parser/functions/load_json.rb
lib/puppet/parser/functions/load_yaml.rb
lib/puppet/parser/functions/lstrip.rb
lib/puppet/parser/functions/member.rb
lib/puppet/parser/functions/type.rb
spec/unit/parser/functions/type_spec.rb

index 0d208b5c903c6dd8b65af8fcc80a9c7b6ef0a441..ab8f75bdb1ecf002cedb4ba3069b7dac861921ec 100644 (file)
@@ -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
 
index 10190ba07f2474324d5984068b52866281a42ab4..3eb4b53756a097f53adcbe3f678b51965d3b06bb 100644 (file)
@@ -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|
 
index 71f8480cc9065a410914a2fcfaf65c29e00ab3a9..4066d210f771c30406853eef5528950a8429ae92 100644 (file)
@@ -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|
 
index e78ebf01c39e4db7796690d3bfe38e9019d7817a..80ebb86b891d3ba83e24fe1cd070d1ab3c7afa79 100644 (file)
@@ -4,6 +4,7 @@
 
 module Puppet::Parser::Functions
   newfunction(:empty, :type => :rvalue, :doc => <<-EOS
+Returns true if the variable is empty.
     EOS
   ) do |arguments|
 
index 6036f7296b9eed601927b2e25750000b021e444d..781da7862d213c8442ee078826b5e97e15f01849 100644 (file)
@@ -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|
 
index 2caaa6f7294a0984cca23e8ba80a5dd67e443362..ceba9ecc8ffc408f96dcaf1b3181c499713ea09b 100644 (file)
@@ -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|
 
index f0c01d4c9a070cdfb7000e6a0d342b723b642a17..453ba1eab6656ea3323294dec27d7d1c9537417f 100644 (file)
@@ -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|
 
index 0b508fd79d754f975f104d2d310f2424696dcf01..b39e184ae5411c3813a9d2d2fd089d85b18e9c7a 100644 (file)
@@ -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|
 
index 8aed8487ea507eee2bf2b9ce215e957d3dbc5a33..2fc05ba9c684b2736c25666bb37d1110b747fbee 100644 (file)
@@ -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|
 
index 000306e92dc5a279ce244c7f4a73a1397ee237b0..ad907f086f33d35b99578fbfe058bff333f4057e 100644 (file)
@@ -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|
 
index 9dd1ceee3c42c018199d1847d4e546063e23f87b..8ee34f6992b2a5129050638f0cd500ecc33af99e 100644 (file)
@@ -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|
 
index c2c0fb51f2b4ff9e293f9ec6860be6130e016ece..ce13eceaa62493c4e35c565d0c5d4e53d15aab8a 100644 (file)
@@ -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|
 
index 8a02a1003e4c957ad3378624c84a529bf2b145b3..f5bef0457f7720ec834b9fe2cfdbed6f4b39cff1 100644 (file)
@@ -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|
 
index 99d6f86985a707e6ecd7a9831be41bf938e36e35..7dd9c0be64f508fae3658e935216d7894e7fcbb8 100644 (file)
@@ -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|
 
index 4f45890a960d7c47a1bf96f1429809b37c6684f0..604d93897455956328b36ace82b4b93f1288cb00 100644 (file)
@@ -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|
 
index a00d87420afacf3376e41e6ec2c602d7e442394a..53199b64af2d1653dce772223a0257469b0a2a41 100644 (file)
@@ -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|
 
index 945556af84353f459b14f046b9e00cdb686e7b53..005a46ea511535a9dae0d26e0e7e65a5a8f45a3b 100644 (file)
@@ -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|
 
index 3a92a47c7aeb796119967bfdb0ac23a939b912c8..f0d13b64760d9c352a54a95d7a68d4826daaf818 100644 (file)
@@ -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|
 
index 7c3f1870833be8f94fb1297cd15307edd2647314..333cf11aa2bbb4de83f7d5a2827bf46dd3a9af7b 100644 (file)
@@ -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|
 
index 1bc2f36f1f3ffd7ef716fcc7d90bbf593698b530..26832772ea0b71914aad378dd93a8646fbd17fc0 100644 (file)
@@ -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|
 
index a7b26565e5d1ec1a9b1cbc004e7f5b6f6cb7427a..3a64de337666ea77aeb1dfa2156e43f15df328f1 100644 (file)
@@ -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|
 
index bb43a37a09ea0e73b0f9a8f3e44628bd8b347708..43d76affd9a5ff873fe3049bf8685c36a9330870 100644 (file)
@@ -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|
 
index de6087e877d32891d53e626b50f29bbc66ede4f9..8d85f11585eb805698fa611a61fcabe29f08f765 100644 (file)
@@ -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
 
index 53071f37a64dc4c5ab6ef258156aef8199341c41..e3c28ed35ffb44c09fbcd63446e382601cb0f26e 100644 (file)
@@ -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