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-retrospec-1.8.0 vendor/pup410/lib/puppet/functions/dig.rb
puppet-retrospec-1.7.0 vendor/pup410/lib/puppet/functions/dig.rb
puppet-4.10.12 lib/puppet/functions/dig.rb
puppet-4.10.12-x86-mingw32 lib/puppet/functions/dig.rb
puppet-4.10.12-x64-mingw32 lib/puppet/functions/dig.rb
puppet-4.10.12-universal-darwin lib/puppet/functions/dig.rb
puppet-4.10.11 lib/puppet/functions/dig.rb
puppet-4.10.11-x86-mingw32 lib/puppet/functions/dig.rb
puppet-4.10.11-x64-mingw32 lib/puppet/functions/dig.rb
puppet-4.10.11-universal-darwin lib/puppet/functions/dig.rb
puppet-4.10.10 lib/puppet/functions/dig.rb
puppet-4.10.10-x86-mingw32 lib/puppet/functions/dig.rb
puppet-4.10.10-x64-mingw32 lib/puppet/functions/dig.rb
puppet-4.10.10-universal-darwin lib/puppet/functions/dig.rb
puppet-retrospec-1.6.1 vendor/pup410/lib/puppet/functions/dig.rb
puppet-retrospec-1.6.0 vendor/pup410/lib/puppet/functions/dig.rb
puppet-4.10.9 lib/puppet/functions/dig.rb
puppet-4.10.9-x86-mingw32 lib/puppet/functions/dig.rb
puppet-4.10.9-x64-mingw32 lib/puppet/functions/dig.rb
puppet-4.10.9-universal-darwin lib/puppet/functions/dig.rb