Class: Chef::ChefFS::FileSystem::Lister
- Inherits:
-
Object
- Object
- Chef::ChefFS::FileSystem::Lister
- Includes:
- Enumerable
- Defined in:
- lib/chef/chef_fs/file_system.rb
Instance Attribute Summary collapse
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(root, pattern) ⇒ Lister
constructor
A new instance of Lister.
- #list_from(entry, &block) ⇒ Object
Constructor Details
Instance Attribute Details
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
47 48 49 |
# File 'lib/chef/chef_fs/file_system.rb', line 47 def pattern @pattern end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
46 47 48 |
# File 'lib/chef/chef_fs/file_system.rb', line 46 def root @root end |
Instance Method Details
#each(&block) ⇒ Object
49 50 51 |
# File 'lib/chef/chef_fs/file_system.rb', line 49 def each(&block) list_from(root, &block) end |
#list_from(entry, &block) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/chef/chef_fs/file_system.rb', line 53 def list_from(entry, &block) # Include self in results if it matches if pattern.match?(entry.display_path) yield(entry) end if pattern.could_match_children?(entry.display_path) # If it's possible that our children could match, descend in and add matches. exact_child_name = pattern.exact_child_name_under(entry.display_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_from(exact_child, &block) end # Otherwise, go through all children and find any matches elsif entry.dir? results = Parallelizer.parallelize(entry.children) { |child| Chef::ChefFS::FileSystem.list(child, pattern) } results.flatten(1).each(&block) end end end |