Module: Sed
- Defined in:
- lib/depengine/processor/sed.rb
Class Method Summary collapse
- .copy(source, target, pattern, replacement) ⇒ Object
- .patch(filename, pattern, replacement) ⇒ Object
Class Method Details
.copy(source, target, pattern, replacement) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/depengine/processor/sed.rb', line 3 def self.copy(source, target, pattern, replacement) if not File.file? source $log.writer.error "File #{source} does not exists" exit 1 end File.open(source, "r:UTF-8") do |source_file| content = source_file.read content.gsub!(pattern, replacement) File.open(target, "w:UTF-8") do |target_file| target_file.write(content) target_file.close end source_file.close end end |
.patch(filename, pattern, replacement) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/depengine/processor/sed.rb', line 21 def self.patch(filename, pattern, replacement) if not File.file? filename $log.writer.error "File #{filename} does not exists" exit 1 end content = "" File.open(filename, "r:UTF-8") do |source_file| content = source_file.read content.gsub!(pattern, replacement) source_file.close end File.open(filename, "w:UTF-8") do |target_file| target_file.write(content) target_file.close end end |