Method: Chef::ChefFS::FileSystem.child_pairs
- Defined in:
- lib/chef/chef_fs/file_system.rb
.child_pairs(a, b) ⇒ Object
Get entries for children of either a or b, with matching pairs matched up.
==== Returns
An array of child pairs.
[ [ a_child, b_child ], ... ]
If a child is only in a or only in b, the other child entry will be retrieved by name (and will most likely be a "nonexistent child").
==== Example
Chef::ChefFS::FileSystem.child_pairs(a, b).length
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/chef/chef_fs/file_system.rb', line 228 def self.child_pairs(a, b) # If both are directories, recurse into them and diff the children instead of returning ourselves. result = [] a_children_names = Set.new a.children.each do |a_child| a_children_names << a_child. result << [ a_child, b.child(a_child.) ] end # Check b for children that aren't in a b.children.each do |b_child| unless a_children_names.include?(b_child.) result << [ a.child(b_child.), b_child ] end end result end |