Module: WolfCore::FileUtils
- Extended by:
- LoggingUtils
- Defined in:
- lib/wolf_core/utils/file_utils.rb
Class Method Summary collapse
- .delete_files(*args) ⇒ Object
- .require_relative_folder(*folders) ⇒ Object
- .safe_require(missing_files) ⇒ Object
Methods included from LoggingUtils
Class Method Details
.delete_files(*args) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/wolf_core/utils/file_utils.rb', line 33 def delete_files(*args) pattern = File.join(*args) files_to_delete = Dir.glob(pattern) files_to_delete.each do |file| File.delete(file) log_object "File deleted: #{file}" end log_object "File Deleting Process Finished! (#{files_to_delete.size} files deleted)" end |
.require_relative_folder(*folders) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/wolf_core/utils/file_utils.rb', line 9 def require_relative_folder(*folders) folder_files = File.join(*folders, '**', '*.rb') files_to_require = Dir[folder_files].sort log_object files_to_require, title: 'Files to require are' safe_require(files_to_require) end |
.safe_require(missing_files) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/wolf_core/utils/file_utils.rb', line 16 def safe_require(missing_files) while missing_files.any? files_to_require = missing_files missing_files = [] files_to_require.each do |file| begin log_object "Requiring file: #{file}" require_relative file rescue NameError => e log_object "Error requiring file: #{file}" log_object e, title: 'Error is' missing_files << file end end end end |