file_backup 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +1 -0
- data/lib/file_backup.rb +18 -0
- data/spec/file_backup_spec.rb +54 -0
- metadata +85 -0
data/README
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Simple file backup mechanism written as extension to File class.
|
data/lib/file_backup.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
class File
|
3
|
+
|
4
|
+
def self.backup(file)
|
5
|
+
rename(file, backup_name(file))
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def self.backup_name(file)
|
11
|
+
backup_number = 0
|
12
|
+
while exist? "#{file}.#{backup_number}.backup" do
|
13
|
+
backup_number += 1
|
14
|
+
end
|
15
|
+
"#{file}.#{backup_number}.backup"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'file_backup'
|
2
|
+
|
3
|
+
describe File do
|
4
|
+
|
5
|
+
let(:the_class) { File }
|
6
|
+
|
7
|
+
describe ".backup" do
|
8
|
+
let(:file) { mock }
|
9
|
+
let(:backup_file) { mock }
|
10
|
+
|
11
|
+
before do
|
12
|
+
the_class.stub!(:backup_name).with(file).and_return(backup_file)
|
13
|
+
the_class.stub!(:rename)
|
14
|
+
end
|
15
|
+
after { the_class.backup(file) }
|
16
|
+
|
17
|
+
it { the_class.should_receive(:rename).with(file, backup_file) }
|
18
|
+
|
19
|
+
it { the_class.should_receive(:backup_name).with(file).and_return(backup_file) }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe ".backup_name" do
|
23
|
+
context "when first file exist" do
|
24
|
+
subject do
|
25
|
+
the_class.stub!(:exist?).with('file.0.backup').and_return(false)
|
26
|
+
the_class.backup_name('file')
|
27
|
+
end
|
28
|
+
|
29
|
+
it { should == 'file.0.backup' }
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when first and second files exist" do
|
33
|
+
subject do
|
34
|
+
the_class.stub!(:exist?).with('file.0.backup').and_return(true)
|
35
|
+
the_class.stub!(:exist?).with('file.1.backup').and_return(false)
|
36
|
+
the_class.backup_name('file')
|
37
|
+
end
|
38
|
+
|
39
|
+
it { should == 'file.1.backup' }
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when first, second and third files exist" do
|
43
|
+
subject do
|
44
|
+
the_class.stub!(:exist?).with('file.0.backup').and_return(true)
|
45
|
+
the_class.stub!(:exist?).with('file.1.backup').and_return(true)
|
46
|
+
the_class.stub!(:exist?).with('file.2.backup').and_return(false)
|
47
|
+
the_class.backup_name('file')
|
48
|
+
end
|
49
|
+
|
50
|
+
it { should == 'file.2.backup' }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: file_backup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Marcin Nowicki
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-28 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Simple file backup mechanism written as extension to File class.
|
36
|
+
email:
|
37
|
+
- pr0d1r2@gmail.com
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
44
|
+
files:
|
45
|
+
- lib/file_backup.rb
|
46
|
+
- spec/file_backup_spec.rb
|
47
|
+
- README
|
48
|
+
has_rdoc: true
|
49
|
+
homepage: http://github.com/doubledrones/file_backup
|
50
|
+
licenses: []
|
51
|
+
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 3
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 23
|
72
|
+
segments:
|
73
|
+
- 1
|
74
|
+
- 3
|
75
|
+
- 6
|
76
|
+
version: 1.3.6
|
77
|
+
requirements: []
|
78
|
+
|
79
|
+
rubyforge_project: file_backup
|
80
|
+
rubygems_version: 1.3.7
|
81
|
+
signing_key:
|
82
|
+
specification_version: 3
|
83
|
+
summary: Simple file backup mechanism written as extension to File class.
|
84
|
+
test_files: []
|
85
|
+
|