Class: Rdm::Utils::FileUtils
- Inherits:
-
Object
- Object
- Rdm::Utils::FileUtils
- Defined in:
- lib/rdm/utils/file_utils.rb
Class Method Summary collapse
Class Method Details
.change_file(original_file, &block) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rdm/utils/file_utils.rb', line 3 def change_file(original_file, &block) return unless block_given? file_name = File.basename(original_file) tmp_file = "/tmp/#{file_name}" File.open(tmp_file, 'w') do |file| File.foreach(original_file) do |line| new_value = yield line || line file.puts new_value end end FileUtils.cp(tmp_file, original_file) FileUtils.rm(tmp_file) end |
.relative_path(path:, from:) ⇒ Object
20 21 22 |
# File 'lib/rdm/utils/file_utils.rb', line 20 def relative_path(path:, from:) Pathname.new(path).relative_path_from(Pathname.new(from)).to_s end |