sparehand 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +2 -0
- data/Manifest.txt +17 -0
- data/README.txt +37 -0
- data/Rakefile +54 -0
- data/bin/comment_block +8 -0
- data/coverage/index.html +259 -0
- data/coverage/lib-comment_block_rb.html +670 -0
- data/lib/comment_block.rb +52 -0
- data/lib/safe_modify.rb +18 -0
- data/lib/sparehand/version.rb +9 -0
- data/setup.rb +1585 -0
- data/test/comment_block_cli_test.rb +28 -0
- data/test/comment_block_test.rb +66 -0
- data/test/fixtures/example_hosts_file +7 -0
- data/test/fixtures/safe_modify_data +1 -0
- data/test/safe_modify_test.rb +28 -0
- data/test/test_helper.rb +8 -0
- metadata +64 -0
data/lib/safe_modify.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
class << File
|
4
|
+
def safe_modify original
|
5
|
+
path = File.dirname(original)
|
6
|
+
temp_name = '.' + File.basename(original) + '.tmp'
|
7
|
+
temp_path = File.join(path, temp_name)
|
8
|
+
|
9
|
+
File.open(original) do |input|
|
10
|
+
File.open(temp_path, 'w') do |output|
|
11
|
+
yield input, output
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
File.delete original
|
16
|
+
File.rename temp_path, original
|
17
|
+
end
|
18
|
+
end
|