file_writer 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e75512a476ab489dc445ed26b71597714b5c9337
4
- data.tar.gz: 0b6811f8bb36e43994157a34134f723d1912b80e
3
+ metadata.gz: 5eddfcd731230df1ecb8a42b44c94eb65ce81aec
4
+ data.tar.gz: 85167825bd894a4af7284fc7c3b37db181df84e5
5
5
  SHA512:
6
- metadata.gz: 22c32936a4a6020bb7a1074d0be3c67e644d18523f4ac11720d2309601812572850fa3b97fdeaee6ff2c90564447bc237be67d4bc44df4ef42ea03692f975b06
7
- data.tar.gz: 64b955399678d05ee7858ee7676d87dc1359414914e411af85178049de3f2110cabb25495b675e4555fe9f0ee9547b067af82c55bd6974332689c6128959a412
6
+ metadata.gz: 9a2993da7a7d9ed78c47a740c77035c64f62dc07aaef5ac9a8fdc68c4d30225ab27ccbd3c2d0c32deacaf0d7568f338cfeed174759d673138757869daa29eba0
7
+ data.tar.gz: d8d0b398b7fa56970992ca2f8faf0eaedc0dc1a708986664075cdc9ac7012e810945bc20f5e7f31199ab544839984ac830b068cbe355bf36d81be8b0a7f0a24e
data/lib/file_writer.rb CHANGED
@@ -21,12 +21,18 @@ class FileWriter
21
21
  #
22
22
  def write(contents)
23
23
  backup = fname + "~"
24
- mode = File.stat(fname).mode
25
24
 
26
- begin
27
- File.rename(fname, backup)
28
- rescue SystemCallError
29
- FileUtils.cp(fname,fname+"~")
25
+ existing = File.exists?(fname)
26
+
27
+ if existing
28
+ mode = File.stat(fname).mode
29
+ begin
30
+ File.rename(fname, backup)
31
+ rescue SystemCallError
32
+ FileUtils.cp(fname,fname+"~")
33
+ end
34
+ else
35
+ mode = nil
30
36
  end
31
37
 
32
38
  File.open(fname, "wb+", mode) do |f|
@@ -1,3 +1,3 @@
1
1
  class FileWriter
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file_writer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vidar Hokstad
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-21 00:00:00.000000000 Z
11
+ date: 2018-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler