Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'tooling/lib/tooling/helpers/file_handler.rb')
-rw-r--r--tooling/lib/tooling/helpers/file_handler.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/tooling/lib/tooling/helpers/file_handler.rb b/tooling/lib/tooling/helpers/file_handler.rb
new file mode 100644
index 00000000000..88248e31df2
--- /dev/null
+++ b/tooling/lib/tooling/helpers/file_handler.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+require 'fileutils'
+
+module Tooling
+ module Helpers
+ module FileHandler
+ def read_array_from_file(file)
+ FileUtils.touch file
+
+ File.read(file).split(' ')
+ end
+
+ def write_array_to_file(file, content_array, append: true)
+ FileUtils.touch file
+
+ # We sort the array to make it easier to read the output file
+ content_array.sort!
+
+ output_content =
+ if append
+ [File.read(file), *content_array].join(' ').lstrip
+ else
+ content_array.join(' ')
+ end
+
+ File.write(file, output_content)
+ end
+ end
+ end
+end