history_file 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/history_file.gemspec +2 -2
- data/lib/history_file.rb +2 -2
- data/lib/history_file/file_delegator.rb +5 -1
- data/lib/history_file/history_file.rb +1 -1
- data/spec/history_file/history_file_spec.rb +23 -16
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/history_file.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "history_file"
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jannis Hermanns"]
|
12
|
-
s.date = "2012-11-
|
12
|
+
s.date = "2012-11-29"
|
13
13
|
s.description = "A File like class that supports versioning by date and has a fallback to older files"
|
14
14
|
s.email = "jannis@moviepilot.com"
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/history_file.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require_relative 'history_file/file_delegator'
|
2
|
+
require_relative 'history_file/history_file'
|
@@ -114,7 +114,11 @@ module HistoryFile
|
|
114
114
|
return false unless @fallback_glob
|
115
115
|
dir = File.dirname(original_filename.to_s)
|
116
116
|
file = File.basename(original_filename.to_s)
|
117
|
-
|
117
|
+
if @subdir
|
118
|
+
glob = File.join(dir, @fallback_glob, file)
|
119
|
+
else
|
120
|
+
glob = File.join(dir, "#{@fallback_glob}-#{file}")
|
121
|
+
end
|
118
122
|
candidates = Dir[glob].sort.select do |c|
|
119
123
|
c < target_filename
|
120
124
|
end.last
|
@@ -36,7 +36,7 @@ module HistoryFile
|
|
36
36
|
def self.[](offset)
|
37
37
|
validate_offset(offset)
|
38
38
|
use_subdirs = @mode == :subdir
|
39
|
-
fallback_glob = "[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9][0-9]
|
39
|
+
fallback_glob = "[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9][0-9]"
|
40
40
|
FileDelegator.new(prefix: prefix(offset),
|
41
41
|
fallback_glob: fallback_glob,
|
42
42
|
use_subdirs: use_subdirs)
|
@@ -97,36 +97,43 @@ describe HistoryFile do
|
|
97
97
|
# We run these tests twice
|
98
98
|
[:subdir, :filename].each do |mode|
|
99
99
|
|
100
|
-
HistoryFile.mode = mode
|
101
100
|
context "falling back to older files in #{mode} mode" do
|
102
|
-
|
103
|
-
|
101
|
+
it "sets up things correctly" do
|
102
|
+
HistoryFile.mode = mode
|
103
|
+
[2,3,6,7,8].each do |i|
|
104
104
|
date = DateTime.now - i
|
105
|
-
HistoryFile[date].open("
|
105
|
+
HistoryFile[date].open("ht_#{mode}.txt", "w") do |file|
|
106
106
|
file.write "Day #{i} #{mode}"
|
107
107
|
end
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
-
|
112
|
-
|
113
|
-
date = DateTime.now - i
|
114
|
-
HistoryFile[date].unlink("ht.txt")
|
115
|
-
end
|
116
|
-
Dir.unlink("some_prefix") rescue nil
|
117
|
-
end
|
118
|
-
|
119
|
-
it "to yesterday's file" do
|
111
|
+
it "to a four days old file" do
|
112
|
+
HistoryFile.mode = mode
|
120
113
|
date = DateTime.now - 4
|
121
|
-
HistoryFile[date].read("
|
114
|
+
HistoryFile[date].read("ht_#{mode}.txt").should == "Day 6 #{mode}"
|
122
115
|
end
|
123
116
|
|
124
117
|
it "to an error if nothing older exists" do
|
118
|
+
HistoryFile.mode = mode
|
125
119
|
expect{
|
126
|
-
date = DateTime.now -
|
127
|
-
HistoryFile[date].read("
|
120
|
+
date = DateTime.now - 9
|
121
|
+
HistoryFile[date].read("ht_#{mode}.txt")
|
128
122
|
}.to raise_error(Errno::ENOENT)
|
129
123
|
end
|
124
|
+
|
125
|
+
it "removes stuff we assumed we created" do
|
126
|
+
HistoryFile.mode = mode
|
127
|
+
[2,3,6,7,8].each do |i|
|
128
|
+
date = DateTime.now - i
|
129
|
+
HistoryFile[date].unlink("ht_#{mode}.txt")
|
130
|
+
if mode == :subdir
|
131
|
+
dir = File.dirname(HistoryFile[date].prefixed_filename("ht_#{mode}.txt"))
|
132
|
+
Dir.unlink(dir)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
130
137
|
end
|
131
138
|
end
|
132
139
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: history_file
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redcarpet
|
@@ -276,7 +276,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
276
276
|
version: '0'
|
277
277
|
segments:
|
278
278
|
- 0
|
279
|
-
hash: -
|
279
|
+
hash: -3732712401603984020
|
280
280
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
281
281
|
none: false
|
282
282
|
requirements:
|