Skip to content

Commit f12e494

Browse files
authored
Merge pull request #922 from hlindberg/(docs)_update-documentation-wrt-functions-moved-to-puppet
(docs) update documentation wrt functions moved to puppet
2 parents 81b95de + 8ded9ad commit f12e494

94 files changed

Lines changed: 649 additions & 63 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 295 additions & 18 deletions
Large diffs are not rendered by default.

lib/puppet/functions/length.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
# A function to eventually replace the old size() function for stdlib - The original size function did not handle Puppets new type capabilities, so this function is a Puppet 4 compatible solution.
1+
# A function to eventually replace the old size() function for stdlib
2+
# The original size function did not handle Puppets new type capabilities, so this function is a Puppet 4 compatible solution.
3+
#
4+
# Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core
5+
# will be used instead of this function.
6+
#
27
Puppet::Functions.create_function(:length) do
38
dispatch :length do
49
param 'Variant[String,Array,Hash]', :value

lib/puppet/functions/sprintf_hash.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
# { 'foo' => 'a string', 'number' => 5 })
1313
# # $output = 'String: a string / number converted to binary: 101'
1414
#
15+
# Note that since Puppet 4.10.10, and 5.3.4 this functionality is supported by the
16+
# `sprintf` function in puppet core.
17+
#
1518
Puppet::Functions.create_function(:sprintf_hash) do
1619
# @param format The format to use.
1720
# @param arguments Hash with parameters.

lib/puppet/parser/functions/abs.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ module Puppet::Parser::Functions
55
newfunction(:abs, :type => :rvalue, :doc => <<-DOC
66
Returns the absolute value of a number, for example -34.56 becomes
77
34.56. Takes a single integer and float value as an argument.
8+
9+
Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core
10+
will be used instead of this function.
811
DOC
912
) do |arguments|
1013

lib/puppet/parser/functions/any2array.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@ module Puppet::Parser::Functions
66
This converts any object to an array containing that object. Empty argument
77
lists are converted to an empty array. Arrays are left untouched. Hashes are
88
converted to arrays of alternating keys and values.
9+
10+
Note that since Puppet 5.0.0 it is possible to create new data types for almost any
11+
datatype using the type system and the built-in
12+
[`Array.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-array-and-tuple)
13+
function is used to create a new Array..
14+
15+
$hsh = {'key' => 42, 'another-key' => 100}
16+
notice(Array($hsh))
17+
18+
Would notice `[['key', 42], ['another-key', 100]]`
19+
20+
The Array data type also has a special mode to "create an array if not already an array"
21+
22+
notice(Array({'key' => 42, 'another-key' => 100}, true))
23+
24+
Would notice `[{'key' => 42, 'another-key' => 100}]`, as the `true` flag prevents the hash from being
25+
transformed into an array.
926
DOC
1027
) do |arguments|
1128

lib/puppet/parser/functions/any2bool.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ module Puppet::Parser::Functions
1111
* Number (or a string representation of a number) > 0 will return true, otherwise false
1212
* undef will return false
1313
* Anything else will return true
14+
15+
Also see the built-in [`Boolean.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-boolean)
16+
function.
1417
DOC
1518
) do |arguments|
1619

lib/puppet/parser/functions/base64.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ module Puppet::Parser::Functions
1313
$encodestring = base64('encode', 'thestring', $method)
1414
$decodestring = base64('decode', 'dGhlc3RyaW5n', $method)
1515
16+
Note: Since Puppet 4.8.0, the Binary data type can be used to produce base 64 encoded strings.
17+
See the `new()` function for the Binary and String types for documentation. Also see `binary_file()`
18+
function for reading a file with binary (non UTF-8) content.
19+
20+
# encode a string as if it was binary
21+
$encodestring = String(Binary('thestring', '%s'))
22+
# decode a Binary assuming it is an UTF-8 String
23+
$decodestring = String(Binary("dGhlc3RyaW5n"), "%s")
24+
1625
DOC
1726

1827
require 'base64'

lib/puppet/parser/functions/bool2num.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ module Puppet::Parser::Functions
77
false, f, 0, n, and no to 0
88
true, t, 1, y, and yes to 1
99
Requires a single boolean or string as an input.
10+
11+
Note that since Puppet 5.0.0 it is possible to create new data types for almost any
12+
datatype using the type system and the built-in
13+
[`Numeric.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-numeric),
14+
[`Integer.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-integer), and
15+
[`Float.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-float)
16+
function are used to convert to numeric values.
17+
18+
notice(Integer(false)) # Notices 0
19+
notice(Float(true)) # Notices 1.0
1020
DOC
1121
) do |arguments|
1222

lib/puppet/parser/functions/bool2str.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ module Puppet::Parser::Functions
1515
bool2str(false, 't', 'f') => 'f'
1616
1717
Requires a single boolean as an input.
18+
19+
Note that since Puppet 5.0.0 it is possible to create new data types for almost any
20+
datatype using the type system and the built-in
21+
[`String.new`](https://puppet.com/docs/puppet/latest/function.html#boolean-to-string)
22+
function is used to convert to String with many different format options.
23+
24+
notice(String(false)) # Notices 'false'
25+
notice(String(true)) # Notices 'true'
26+
notice(String(false, '%y')) # Notices 'yes'
27+
notice(String(true, '%y')) # Notices 'no'
28+
1829
DOC
1930
) do |arguments|
2031

lib/puppet/parser/functions/camelcase.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
module Puppet::Parser::Functions
66
newfunction(:camelcase, :type => :rvalue, :doc => <<-DOC
77
Converts the case of a string or all strings in an array to camel case.
8+
9+
Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core
10+
will be used instead of this function.
811
DOC
912
) do |arguments|
1013

0 commit comments

Comments
 (0)