Method: Chef::Node#deep_fetch!
- Defined in:
- lib/chef/sugar/node.rb
#deep_fetch!(*keys) ⇒ Object
Deeply fetch a node attribute by specifying a list of keys, bypassing Ruby’s Hash notation.
This method will raise any exceptions, such as undefined method ‘[]’ for nil:NilClass, just as if you used the native attribute notation. If you want a safely vivified hash, see #deep_fetch.
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/chef/sugar/node.rb', line 73 def deep_fetch!(*keys) keys.map!(&:to_s) keys.inject(attributes.to_hash) do |hash, key| if hash.key?(key) hash[key] else raise AttributeDoesNotExistError.new(keys, key) end end end |