Method: Chef::ChefFS::FileSystem.list

Defined in:
lib/chef/chef_fs/file_system.rb

.list(entry, pattern, &block) ⇒ Object

Yields a list of all things under (and including) this entry that match the given pattern.

Attributes

  • entry - Entry to start listing under

  • pattern - Chef::ChefFS::FilePattern to match children under



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/chef/chef_fs/file_system.rb', line 32

def self.list(entry, pattern, &block)
  # Include self in results if it matches
  if pattern.match?(entry.path)
    block.call(entry)
  end

  if entry.dir? && pattern.could_match_children?(entry.path)
    # If it's possible that our children could match, descend in and add matches.
    exact_child_name = pattern.exact_child_name_under(entry.path)

    # If we've got an exact name, don't bother listing children; just grab the
    # child with the given name.
    if exact_child_name
      exact_child = entry.child(exact_child_name)
      if exact_child
        list(exact_child, pattern, &block)
      end

    # Otherwise, go through all children and find any matches
    else
      entry.children.each do |child|
        list(child, pattern, &block)
      end
    end
  end
end