Method: Chef::NodeMap#delete_class
- Defined in:
- lib/chef/node_map.rb
#delete_class(klass) ⇒ Hash
Remove a class from all its matchers in the node_map, will remove mappings completely if its the last matcher left
Note that this leaks the internal structure out a bit, but the main consumer of this (poise/halite) cares only about the keys in the returned Hash.
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/chef/node_map.rb', line 156 def delete_class(klass) raise "please use a Class type for the klass argument" unless klass.is_a?(Class) deleted = {} map.each do |key, matchers| deleted_matchers = [] matchers.delete_if do |matcher| # because matcher[:klass] may be a string (which needs to die), coerce both to strings to compare somewhat canonically if matcher[:klass].to_s == klass.to_s deleted_matchers << matcher true end end deleted[key] = deleted_matchers unless deleted_matchers.empty? map.delete(key) if matchers.empty? end deleted end |