adrian 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/adrian/file_item.rb +20 -6
- data/lib/adrian/version.rb +1 -1
- data/test/file_item_test.rb +59 -0
- metadata +4 -4
data/lib/adrian/file_item.rb
CHANGED
@@ -2,9 +2,9 @@ module Adrian
|
|
2
2
|
class FileItem < QueueItem
|
3
3
|
attr_accessor :logger
|
4
4
|
|
5
|
-
def initialize(value
|
5
|
+
def initialize(value)
|
6
6
|
@value = value
|
7
|
-
|
7
|
+
created_at
|
8
8
|
updated_at
|
9
9
|
end
|
10
10
|
|
@@ -28,15 +28,29 @@ module Adrian
|
|
28
28
|
@value = destination_path
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
32
|
-
|
31
|
+
def atime
|
32
|
+
File.atime(path).utc
|
33
|
+
rescue Errno::ENOENT
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
|
37
|
+
def mtime
|
38
|
+
File.mtime(path).utc
|
33
39
|
rescue Errno::ENOENT
|
34
40
|
nil
|
35
41
|
end
|
36
42
|
|
43
|
+
def updated_at
|
44
|
+
@updated_at ||= atime
|
45
|
+
end
|
46
|
+
|
47
|
+
def created_at
|
48
|
+
@created_at ||= mtime
|
49
|
+
end
|
50
|
+
|
37
51
|
def touch(updated_at = Time.new)
|
38
|
-
@updated_at = updated_at
|
39
|
-
File.utime(updated_at,
|
52
|
+
@updated_at = updated_at.utc
|
53
|
+
File.utime(updated_at, created_at, path)
|
40
54
|
end
|
41
55
|
|
42
56
|
def exist?
|
data/lib/adrian/version.rb
CHANGED
data/test/file_item_test.rb
CHANGED
@@ -27,6 +27,10 @@ describe Adrian::FileItem do
|
|
27
27
|
|
28
28
|
describe 'updated_at' do
|
29
29
|
|
30
|
+
it 'is the atime of the file' do
|
31
|
+
@item.updated_at.must_equal File.atime(@item.path)
|
32
|
+
end
|
33
|
+
|
30
34
|
it 'is nil when moved by another process' do
|
31
35
|
item = Adrian::FileItem.new('moved/during/initialize')
|
32
36
|
assert_equal false, item.exist?
|
@@ -44,6 +48,29 @@ describe Adrian::FileItem do
|
|
44
48
|
|
45
49
|
end
|
46
50
|
|
51
|
+
describe 'created_at' do
|
52
|
+
|
53
|
+
it 'is the mtime of the file' do
|
54
|
+
@item.created_at.must_equal File.mtime(@item.path)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'is nil when moved by another process' do
|
58
|
+
item = Adrian::FileItem.new('moved/during/initialize')
|
59
|
+
assert_equal false, item.exist?
|
60
|
+
assert_equal nil, item.created_at
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'is cached' do
|
64
|
+
created_at = @item.created_at
|
65
|
+
assert @item.created_at
|
66
|
+
File.unlink(@item.path)
|
67
|
+
assert_equal false, @item.exist?
|
68
|
+
|
69
|
+
assert_equal created_at, @item.created_at
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
47
74
|
describe 'move' do
|
48
75
|
before do
|
49
76
|
@destination = Dir.mktmpdir('file_item_move_test')
|
@@ -70,6 +97,18 @@ describe Adrian::FileItem do
|
|
70
97
|
logger.verify
|
71
98
|
end
|
72
99
|
|
100
|
+
it 'does not change the atime' do
|
101
|
+
atime = File.atime(@item.path)
|
102
|
+
@item.move(@destination)
|
103
|
+
File.atime(@item.path).must_equal atime
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'does not change the mtime' do
|
107
|
+
mtime = File.mtime(@item.path)
|
108
|
+
@item.move(@destination)
|
109
|
+
File.mtime(@item.path).must_equal mtime
|
110
|
+
end
|
111
|
+
|
73
112
|
end
|
74
113
|
|
75
114
|
describe 'touch' do
|
@@ -81,6 +120,26 @@ describe Adrian::FileItem do
|
|
81
120
|
assert_equal now.to_i, @item.updated_at.to_i
|
82
121
|
end
|
83
122
|
|
123
|
+
it 'changes the atime' do
|
124
|
+
atime = File.atime(@item.path).to_i
|
125
|
+
|
126
|
+
now = (Time.now - 100)
|
127
|
+
Time.stub(:new, now) { @item.touch }
|
128
|
+
|
129
|
+
now.to_i.wont_equal atime
|
130
|
+
File.atime(@item.path).to_i.must_equal now.to_i
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'does not change the mtime' do
|
134
|
+
mtime = File.mtime(@item.path).to_i
|
135
|
+
|
136
|
+
now = (Time.now - 100)
|
137
|
+
Time.stub(:new, now) { @item.touch }
|
138
|
+
|
139
|
+
now.to_i.wont_equal mtime
|
140
|
+
File.mtime(@item.path).to_i.must_equal mtime
|
141
|
+
end
|
142
|
+
|
84
143
|
end
|
85
144
|
|
86
145
|
it 'exists when the file at the given path exists' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adrian
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-10-
|
13
|
+
date: 2012-10-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
@@ -125,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
125
|
version: '0'
|
126
126
|
segments:
|
127
127
|
- 0
|
128
|
-
hash:
|
128
|
+
hash: -3817287856901021378
|
129
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
130
|
none: false
|
131
131
|
requirements:
|
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
134
|
version: '0'
|
135
135
|
segments:
|
136
136
|
- 0
|
137
|
-
hash:
|
137
|
+
hash: -3817287856901021378
|
138
138
|
requirements: []
|
139
139
|
rubyforge_project:
|
140
140
|
rubygems_version: 1.8.24
|