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.
49 50 51 |
# File 'lib/chef/chef_fs/file_system.rb', line 49 def pattern @pattern end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
48 49 50 |
# File 'lib/chef/chef_fs/file_system.rb', line 48 def root @root end |
Instance Method Details
#each(&block) ⇒ Object
51 52 53 |
# File 'lib/chef/chef_fs/file_system.rb', line 51 def each(&block) list_from(root, &block) end |
#list_from(entry, &block) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/chef/chef_fs/file_system.rb', line 55 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 = entry.children.parallel_map { |child| Chef::ChefFS::FileSystem.list(child, pattern) } results.flat_each(&block) end end end |