Class: SlimKeyfy::Slimutils::MFileUtils
- Defined in:
- lib/slimkeyfy/slimutils/file_utils.rb
Class Method Summary collapse
- .abs_path(file) ⇒ Object
- .backup(input) ⇒ Object
- .create_new_file(input) ⇒ Object
- .file_extension(file_path) ⇒ Object
- .is_valid_extension?(file_path) ⇒ Boolean
- .restore(backup_path, original_file_path) ⇒ Object
- .rm(file_path) ⇒ Object
- .walk(arg, recursive = false) ⇒ Object
Class Method Details
.abs_path(file) ⇒ Object
23 24 25 |
# File 'lib/slimkeyfy/slimutils/file_utils.rb', line 23 def self.abs_path(file) File.absolute_path(file) end |
.backup(input) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/slimkeyfy/slimutils/file_utils.rb', line 12 def self.backup(input) original_file_path = abs_path(input) backup_path = "#{original_file_path}.bak" FileUtils.cp(original_file_path, backup_path) backup_path end |
.create_new_file(input) ⇒ Object
18 19 20 21 22 |
# File 'lib/slimkeyfy/slimutils/file_utils.rb', line 18 def self.create_new_file(input) new_file_path = self.abs_path(input) SlimKeyfy::Slimutils::FileWriter.write(new_file_path, "") new_file_path end |
.file_extension(file_path) ⇒ Object
38 39 40 |
# File 'lib/slimkeyfy/slimutils/file_utils.rb', line 38 def self.file_extension(file_path) file_path.split(".").last end |
.is_valid_extension?(file_path) ⇒ Boolean
41 42 43 44 |
# File 'lib/slimkeyfy/slimutils/file_utils.rb', line 41 def self.is_valid_extension?(file_path) return false if (file_path.nil? or file_path.empty?) (file_path.end_with?(".slim") or file_path.end_with?(".rb")) end |
.restore(backup_path, original_file_path) ⇒ Object
5 6 7 8 |
# File 'lib/slimkeyfy/slimutils/file_utils.rb', line 5 def self.restore(backup_path, original_file_path) FileUtils.cp(backup_path, original_file_path) FileUtils.rm(backup_path) end |
.rm(file_path) ⇒ Object
9 10 11 |
# File 'lib/slimkeyfy/slimutils/file_utils.rb', line 9 def self.rm(file_path) FileUtils.rm(file_path) end |
.walk(arg, recursive = false) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/slimkeyfy/slimutils/file_utils.rb', line 26 def self.walk(arg, recursive=false) directory = abs_path(arg) files = [] if recursive then Find.find(directory) do |f| files << f if File.file?(f) end else files = Dir["#{directory}/*"] end files end |