Class: Scanner
- Inherits:
-
Object
- Object
- Scanner
- Defined in:
- lib/tree/scanner.rb
Overview
Scanner class scan all directories of root array and return all children
Instance Method Summary collapse
- #scan(path_array, directories, files, tree_data, root) ⇒ Object
- #scan_multithread(path_array, directories, files, tree_data, root) ⇒ Object
Instance Method Details
#scan(path_array, directories, files, tree_data, root) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/tree/scanner.rb', line 7 def scan(path_array, directories, files, tree_data, root) folders_arr = [] path_array.each do |i| if i.file? files += 1 next else directories += 1 begin i.each_child do |dir| folders_arr << dir tree_data << dir i = dir end rescue Errno::EACCES, Errno::ENOENT, Errno::ENOTDIR next end end end if folders_arr.empty? [tree_data, root, files, directories] else scan(folders_arr, directories, files, tree_data, root) end end |
#scan_multithread(path_array, directories, files, tree_data, root) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/tree/scanner.rb', line 33 def scan_multithread(path_array, directories, files, tree_data, root) threads = [] path_array.each do |n| threads << Thread.new do n.find do |v| next if v == n tree_data << v if v.file? files += 1 else directories += 1 end end end end threads.each(&:join) [tree_data, root, files, directories] end |