generated from appdev-projects/rails-7-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadd_comment_to_files.rb
34 lines (31 loc) · 966 Bytes
/
add_comment_to_files.rb
1
2
3
4
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
30
31
32
33
34
# frozen_string_literal: true
# /workspaces/Inventory-Management-System/add_comment_to_files.rb
def add_comment_to_file(file_path)
comment_char, comment_end = comment_chars_for_file(file_path)
comment = "#{comment_char}#{file_path}#{comment_end}"
content = File.read(file_path)
content = "#{comment}\n#{content}"
File.write(file_path, content)
end
def comment_chars_for_file(file_path)
case File.extname(file_path)
when ".rb"
["#", ""]
when ".js"
["//", ""]
when ".css"
["/* ", ""]
when ".html"
["<!--", "-->"]
when ".erb"
["<!--", "-->"]
end
end
def process_files(directory, extensions)
Dir.glob(File.join(directory, "**/*.{#{extensions.join(",")}}")).each do |file|
add_comment_to_file(file)
end
end
directory_to_search = "/workspaces/Inventory-Management-System/"
file_extensions = ["rb", "html", "html.erb", "css", "js"]
process_files(directory_to_search, file_extensions)