Sha256: 6c610b85242441a0bf3397f663b7771554beacb78671258f84c3725fa01fcdee

Contents?: true

Size: 549 Bytes

Versions: 96

Compression:

Stored size: 549 Bytes

Contents

# Digs into a data structure.
# (Documented in 3.x stub)
#
# @since 4.5.0
#
Puppet::Functions.create_function(:dig) do
  dispatch :dig do
    param 'Optional[Collection]', :data
    repeated_param 'Any', :arg
  end

  def dig(data, *args)
    walked_path = []
    args.reduce(data) do | d, k |
      return nil if d.nil? || k.nil?
      if !(d.is_a?(Array) || d.is_a?(Hash))
        raise ArgumentError, "The given data does not contain a Collection at #{walked_path}, got '#{d.class}'"
      end
      walked_path << k
      d[k]
    end
  end
end

Version data entries

96 entries across 96 versions & 2 rubygems

Version Path
puppet-4.8.0 lib/puppet/functions/dig.rb
puppet-4.8.0-x86-mingw32 lib/puppet/functions/dig.rb
puppet-4.8.0-x64-mingw32 lib/puppet/functions/dig.rb
puppet-4.8.0-universal-darwin lib/puppet/functions/dig.rb
puppet-4.7.0 lib/puppet/functions/dig.rb
puppet-4.7.0-x86-mingw32 lib/puppet/functions/dig.rb
puppet-4.7.0-x64-mingw32 lib/puppet/functions/dig.rb
puppet-4.7.0-universal-darwin lib/puppet/functions/dig.rb
puppet-4.6.2 lib/puppet/functions/dig.rb
puppet-4.6.2-x86-mingw32 lib/puppet/functions/dig.rb
puppet-4.6.2-x64-mingw32 lib/puppet/functions/dig.rb
puppet-4.6.2-universal-darwin lib/puppet/functions/dig.rb
puppet-4.6.1-x86-mingw32 lib/puppet/functions/dig.rb
puppet-4.6.1 lib/puppet/functions/dig.rb
puppet-4.6.1-x64-mingw32 lib/puppet/functions/dig.rb
puppet-4.6.1-universal-darwin lib/puppet/functions/dig.rb