Top Level Namespace

Defined Under Namespace

Modules: HeaderUtil

Instance Method Summary collapse

Instance Method Details

#traverse(start, header, update) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/headerutil/util.rb', line 24

def traverse(start, header, update)
  file_array = []
  Dir.foreach(start) do |x|
    path = File.join(start, x)
    if x == "." or x == ".."
      next
    elsif File.directory?(path)
      loop_in = 1
      $ignore_folders.each() do |exclusion|
        $ignored_path = $search_folder + exclusion
        if path == $ignored_path
          loop_in = 0
          break
        end
      end

      if loop_in == 1
        inner_files_array = traverse(path, header, update)
        if inner_files_array.length > 0
          file_array = file_array + inner_files_array
        end
      end
    else
      file_ext = File.extname(x)
      if $accepted_formats.keys.include? file_ext
        if File.readlines(path).grep(/#{header}/).size <= 0
          if update
          `echo "#{$accepted_formats[file_ext][:prefix]} #{header} #{$accepted_formats[file_ext][:suffix]} \n" | cat - #{path} > #{path}.new.temp && mv #{path}.new.temp #{path}`
          end
          file_array.push(path)
        end
      end
    end
  end
  return file_array
end