Method: Chef::Node#deep_fetch

Defined in:
lib/chef/sugar/node.rb

#deep_fetch(*keys) ⇒ Object

Safely fetch a deeply nested attribute by specifying a list of keys, bypassing Ruby’s Hash notation. This method swallows NoMethodError exceptions, avoiding the most common error in Chef-land.

This method will return nil if any deeply nested key does not exist.

See Also:

  • Chef::Node.[Node[Node#deep_fetch!]


51
52
53
54
55
# File 'lib/chef/sugar/node.rb', line 51

def deep_fetch(*keys)
  deep_fetch!(*keys)
rescue NoMethodError, AttributeDoesNotExistError
  nil
end