Method: Falsework::Mould.traverse
- Defined in:
- lib/falsework/mould.rb
.traverse(start, &block) ⇒ Object
Walk through a directory tree, executing a block for each file or directory. Ignores ., .. and files starting with _#_ character.
- start
-
The directory to start with.
302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/falsework/mould.rb', line 302 def self.traverse(start, &block) l = Dir.glob(start + '/*', File::FNM_DOTMATCH).delete_if {|i| i.match(/\/?\.\.?$/) || i.match(/^#|\/#/) } # stop if directory is empty (contains only . and ..) return if l.size == 0 l.sort.each {|i| yield i # recursion! self.traverse(i) {|j| block.call j} if File.directory?(i) } end |