Ignore:
Timestamp:
Aug 1, 2017, 3:45:14 PM (9 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
debian/bullseye, debian/jessie
Children:
ce0f6a4
Parents:
bcf0be5 (diff), cd0f9cc (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into debian/jessie

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/puppetcode/environments/gnuboat/modules/stdlib/lib/puppet/parser/functions/dig.rb

    rbcf0be5 rad28f83  
    55module Puppet::Parser::Functions
    66  newfunction(:dig, :type => :rvalue, :doc => <<-EOS
    7 Looks up into a complex structure of arrays and hashes and returns nil
    8 or the default value if nothing was found.
    9 
    10 Path is an array of keys to be looked up in data argument. The function
    11 will go down the structure and try to extract the required value.
    12 
    13 $data = {
    14   'a' => {
    15     'b' => [
    16       'b1',
    17       'b2',
    18       'b3' ]}}
    19 
    20 $value = dig($data, ['a', 'b', '2'], 'not_found')
    21 => $value = 'b3'
    22 
    23 a -> first hash key
    24 b -> second hash key
    25 2 -> array index starting with 0
    26 
    27 not_found -> (optional) will be returned if there is no value or the path
    28 did not match. Defaults to nil.
    29 
    30 In addition to the required "path" argument, "dig" accepts default
    31 argument. It will be returned if no value was found or a path component is
    32 missing. And the fourth argument can set a variable path separator.
     7    DEPRECATED: This function has been replaced in Puppet 4.5.0, please use dig44() for backwards compatibility or use the new version.
    338    EOS
    34              ) do |arguments|
    35     # Two arguments are required
    36     raise(Puppet::ParseError, "dig(): Wrong number of arguments " +
    37                               "given (#{arguments.size} for at least 2)") if arguments.size < 2
    38 
    39     data, path, default = *arguments
    40 
    41     if !(data.is_a?(Hash) || data.is_a?(Array))
    42       raise(Puppet::ParseError, "dig(): first argument must be a hash or an array, " <<
    43                                 "given #{data.class.name}")
     9  ) do |arguments|
     10    warning("dig() DEPRECATED: This function has been replaced in Puppet 4.5.0, please use dig44() for backwards compatibility or use the new version.")
     11    if ! Puppet::Parser::Functions.autoloader.loaded?(:dig44)
     12      Puppet::Parser::Functions.autoloader.load(:dig44)
    4413    end
    45 
    46     unless path.is_a? Array
    47       raise(Puppet::ParseError, "dig(): second argument must be an array, " <<
    48                                 "given #{path.class.name}")
    49     end
    50 
    51     value = path.reduce(data) { |h, k| (h.is_a?(Hash) || h.is_a?(Array)) ? h[k] : break }
    52     value.nil? ? default : value
     14    function_dig44(arguments)
    5315  end
    5416end
Note: See TracChangeset for help on using the changeset viewer.