Skip to content

Commit 9d5478d

Browse files
committed
[API] Generator - Fixes emptying directory
Turns out Thor's `empty_directory` creates an empty directory, it does not delete files in it. This is going to help deleting deprecated/unexistent endpoints and updating renames in endpoints in the future.
1 parent f44519b commit 9d5478d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

elasticsearch-api/utils/thor/generate_source.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def generate
6161

6262
def generate_source
6363
@output = FilesHelper.output_dir
64+
cleanup_directory!
6465

6566
FilesHelper.files.each do |filepath|
6667
@path = Pathname(filepath)
@@ -91,6 +92,7 @@ def generate_source
9192

9293
@path_to_file = @output.join(@module_namespace.join('/')).join("#{@method_name}.rb")
9394
dir = @output.join(@module_namespace.join('/'))
95+
9496
empty_directory(dir, verbose: false)
9597

9698
# Write the file with the ERB template:
@@ -287,6 +289,13 @@ def print_tree
287289
say_status('tree', lines.first + "\n" + lines[1, lines.size].map { |l| ' ' * 14 + l }.join("\n"))
288290
end
289291

292+
def cleanup_directory!
293+
Dir["#{@output}/**/*.rb"].each do |file|
294+
# file = File.join(@output, f)
295+
File.delete(file) unless (['.', '..'].include? file) || Pathname(file).directory?
296+
end
297+
end
298+
290299
def run_rubocop
291300
system("rubocop -c ./thor/.rubocop.yml --format autogenconf -x #{FilesHelper::output_dir}")
292301
end

0 commit comments

Comments
 (0)