Module: AgileUtils::FileUtil
- Defined in:
- lib/agile_utils/file_util.rb
Constant Summary collapse
- CustomError =
Class.new(StandardError)
Class Method Summary collapse
-
.delete(files) ⇒ Object
Delete the files from the given list.
-
.find(base_dir, extension = "xhtml") ⇒ Array<String>
Find list of files based on certain extension.
-
.gunzip(filename, output_dir) ⇒ Object
Uncompress ‘input.tar.gz’ file.
-
.tar_gzip_files(files, output = "output.tar.gz") ⇒ Object
Tar and gzip list of files.
-
.time ⇒ Object
Time the operation before and after the operation for tuning purpose.
Class Method Details
.delete(files) ⇒ Object
Delete the files from the given list
52 53 54 55 56 |
# File 'lib/agile_utils/file_util.rb', line 52 def delete(files) files.each do |file| FileUtils.rm_rf(file) end end |
.find(base_dir, extension = "xhtml") ⇒ Array<String>
Find list of files based on certain extension
rubocop:disable CollectionMethods
14 15 16 17 18 19 20 |
# File 'lib/agile_utils/file_util.rb', line 14 def find(base_dir, extension = "xhtml") file_paths = [] Find.find(base_dir) do |path| file_paths << path if path =~ /.*\.#{extension}$/ end file_paths end |
.gunzip(filename, output_dir) ⇒ Object
Uncompress ‘input.tar.gz’ file
43 44 45 46 47 |
# File 'lib/agile_utils/file_util.rb', line 43 def gunzip(filename, output_dir) input_file = File.open(filename, "rb") tgz = Zlib::GzipReader.new(input_file) Archive::Tar::Minitar.unpack(tgz, output_dir) end |
.tar_gzip_files(files, output = "output.tar.gz") ⇒ Object
TODO:
rename to tar_gzip(..)
Tar and gzip list of files
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/agile_utils/file_util.rb', line 28 def tar_gzip_files(files, output = "output.tar.gz") sgz = Zlib::GzipWriter.new(File.open(output, "wb")) tar = Archive::Tar::Minitar::Output.new(sgz) files.each do |file| Archive::Tar::Minitar.pack_file(file, tar) end ensure tar.close unless tar.nil? tar = nil end |
.time ⇒ Object
Time the operation before and after the operation for tuning purpose
59 60 61 62 63 64 |
# File 'lib/agile_utils/file_util.rb', line 59 def time beg_time = Time.now yield end_time = Time.now end_time - beg_time end |