Module: FS::Find
- Included in:
- FS
- Defined in:
- lib/fs/find.rb
Instance Method Summary collapse
-
#find(dir, options = {}, &block) ⇒ Object
Find::find.
- #find_dirs(dir, options = {}, &block) ⇒ Object
- #find_files(dir, options = {}, &block) ⇒ Object
Instance Method Details
#find(dir, options = {}, &block) ⇒ Object
Find::find
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fs/find.rb', line 5 def find(dir, ={}, &block) defaults = { :current => false, :absolute => false, :condition => nil } = defaults.merge() result = [] full_dir = File.(dir) ::Find.find(dir) do |full_path| next if ![:current] && full_path == full_dir path = [:absolute] ? full_path : FS.chop(full_path, full_dir) next if [:condition] && ![:condition][path] if block block[path] else result << path end end block ? nil : result end |
#find_dirs(dir, options = {}, &block) ⇒ Object
31 32 33 34 |
# File 'lib/fs/find.rb', line 31 def find_dirs(dir, ={}, &block) condition = ->(path){FileTest.directory?(path)} find(dir, .merge(:condition => condition), &block) end |
#find_files(dir, options = {}, &block) ⇒ Object
36 37 38 39 |
# File 'lib/fs/find.rb', line 36 def find_files(dir, ={}, &block) condition = ->(path){!FileTest.directory?(path)} find(dir, .merge(:condition => condition), &block) end |