summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Schmitt <david.schmitt@puppet.com>2016-07-13 09:50:30 +0100
committerGitHub <noreply@github.com>2016-07-13 09:50:30 +0100
commit9224143da2195c57ce814e837f722348c2038ecb (patch)
tree5b2aa1370903527e27428399500ec9a78b9a3e84 /lib
parente723c7c292dbc1b1792798a4c70d58937d412b13 (diff)
parenta2f980d44d6703561769c5e0ef25a7f531417643 (diff)
Merge pull request #618 from ntpttr/fix/master/modules-3568
(MODULES-3568) Move dig to dig44 and deprecate dig
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/parser/functions/dig.rb50
-rw-r--r--lib/puppet/parser/functions/dig44.rb56
2 files changed, 62 insertions, 44 deletions
diff --git a/lib/puppet/parser/functions/dig.rb b/lib/puppet/parser/functions/dig.rb
index a9aa770..34fa701 100644
--- a/lib/puppet/parser/functions/dig.rb
+++ b/lib/puppet/parser/functions/dig.rb
@@ -4,51 +4,13 @@
module Puppet::Parser::Functions
newfunction(:dig, :type => :rvalue, :doc => <<-EOS
-Looks up into a complex structure of arrays and hashes and returns nil
-or the default value if nothing was found.
-
-Path is an array of keys to be looked up in data argument. The function
-will go down the structure and try to extract the required value.
-
-$data = {
- 'a' => {
- 'b' => [
- 'b1',
- 'b2',
- 'b3' ]}}
-
-$value = dig($data, ['a', 'b', '2'], 'not_found')
-=> $value = 'b3'
-
-a -> first hash key
-b -> second hash key
-2 -> array index starting with 0
-
-not_found -> (optional) will be returned if there is no value or the path
-did not match. Defaults to nil.
-
-In addition to the required "path" argument, "dig" accepts default
-argument. It will be returned if no value was found or a path component is
-missing. And the fourth argument can set a variable path separator.
+ DEPRECATED: This function has been replaced in Puppet 4.5.0, please use dig44() for backwards compatibility or use the new version.
EOS
- ) do |arguments|
- # Two arguments are required
- raise(Puppet::ParseError, "dig(): Wrong number of arguments " +
- "given (#{arguments.size} for at least 2)") if arguments.size < 2
-
- data, path, default = *arguments
-
- if !(data.is_a?(Hash) || data.is_a?(Array))
- raise(Puppet::ParseError, "dig(): first argument must be a hash or an array, " <<
- "given #{data.class.name}")
+ ) do |arguments|
+ warning("dig() DEPRECATED: This function has been replaced in Puppet 4.5.0, please use dig44() for backwards compatibility or use the new version.")
+ if ! Puppet::Parser::Functions.autoloader.loaded?(:dig44)
+ Puppet::Parser::Functions.autoloader.load(:dig44)
end
-
- unless path.is_a? Array
- raise(Puppet::ParseError, "dig(): second argument must be an array, " <<
- "given #{path.class.name}")
- end
-
- value = path.reduce(data) { |h, k| (h.is_a?(Hash) || h.is_a?(Array)) ? h[k] : break }
- value.nil? ? default : value
+ function_dig44(arguments)
end
end
diff --git a/lib/puppet/parser/functions/dig44.rb b/lib/puppet/parser/functions/dig44.rb
new file mode 100644
index 0000000..a7de363
--- /dev/null
+++ b/lib/puppet/parser/functions/dig44.rb
@@ -0,0 +1,56 @@
+#
+# dig44.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:dig44, :type => :rvalue, :doc => <<-EOS
+DEPRECATED: This function has been replaced in puppet 4.5.0.
+
+Looks up into a complex structure of arrays and hashes and returns nil
+or the default value if nothing was found.
+
+Path is an array of keys to be looked up in data argument. The function
+will go down the structure and try to extract the required value.
+
+$data = {
+ 'a' => {
+ 'b' => [
+ 'b1',
+ 'b2',
+ 'b3' ]}}
+
+$value = dig44($data, ['a', 'b', '2'], 'not_found')
+=> $value = 'b3'
+
+a -> first hash key
+b -> second hash key
+2 -> array index starting with 0
+
+not_found -> (optional) will be returned if there is no value or the path
+did not match. Defaults to nil.
+
+In addition to the required "path" argument, "dig44" accepts default
+argument. It will be returned if no value was found or a path component is
+missing. And the fourth argument can set a variable path separator.
+ EOS
+ ) do |arguments|
+ # Two arguments are required
+ raise(Puppet::ParseError, "dig44(): Wrong number of arguments " +
+ "given (#{arguments.size} for at least 2)") if arguments.size < 2
+
+ data, path, default = *arguments
+
+ if !(data.is_a?(Hash) || data.is_a?(Array))
+ raise(Puppet::ParseError, "dig44(): first argument must be a hash or an array, " <<
+ "given #{data.class.name}")
+ end
+
+ unless path.is_a? Array
+ raise(Puppet::ParseError, "dig44(): second argument must be an array, " <<
+ "given #{path.class.name}")
+ end
+
+ value = path.reduce(data) { |h, k| (h.is_a?(Hash) || h.is_a?(Array)) ? h[k] : break }
+ value.nil? ? default : value
+ end
+end