Method: Pathname#visit
- Defined in:
- lib/standard/facets/pathname/visit.rb
#visit(options = {:all => false, :hidden => false}) ⇒ Object
Recursively visit a directory located by its path, yielding each resource as its full matching pathname object. If called on a file, yield the file.
call-seq:
visit => yield each file
visit(all: true) => yield visited directories as well
visit(hidden: true) => yield hidden files and directories as well
Examples
# Locate any file but *.haml within app/**/*
Pathname.new("app").visit do |f|
next unless f.to_s =~ /\.haml$/
f
end
TODO: Use #map instead of #each?
CREDIT: Jean-Denis Vauguet
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/standard/facets/pathname/visit.rb', line 23 def visit( = {:all => false, :hidden => false}) if self.directory? children.each do |entry| next if entry.basename.to_s[0] == "." && ![:hidden] yield(entry) unless entry.directory? && ![:all] ##entry.visit(:all => options[:all]) { |sub_entry| yield sub_entry } if entry.directory? entry.visit(:all => [:all], :hidden => [:hidden]) do |sub_entry| yield(sub_entry) end if entry.directory? end else yield self end end |