ptools 1.1.5 → 1.1.6
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/CHANGES +5 -0
- data/lib/ptools.rb +9 -3
- data/test/tc_constants.rb +1 -1
- data/test/tc_touch.rb +10 -1
- metadata +2 -2
data/CHANGES
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
== 1.1.6 - 31-Aug-2007
|
2
|
+
* Fixed the File.touch method so that it doesn't whack existing files. Thanks
|
3
|
+
go to Thomas Preymesser for the spot.
|
4
|
+
* Added corresponding tests to the tc_touch.rb file.
|
5
|
+
|
1
6
|
== 1.1.5 - 19-Jul-2007
|
2
7
|
* Added the File.image? method. Inspired by ruby-talk: 260487.
|
3
8
|
|
data/lib/ptools.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'win32/file' if RUBY_PLATFORM.match('mswin')
|
2
2
|
|
3
3
|
class File
|
4
|
-
PTOOLS_VERSION = '1.1.
|
4
|
+
PTOOLS_VERSION = '1.1.6'
|
5
5
|
|
6
6
|
# :stopdoc:
|
7
7
|
|
@@ -243,10 +243,16 @@ class File
|
|
243
243
|
self
|
244
244
|
end
|
245
245
|
|
246
|
-
#
|
246
|
+
# Changes the access and modification time if present, or creates a 0
|
247
|
+
# byte file +filename+ if it doesn't already exist.
|
247
248
|
#
|
248
249
|
def self.touch(filename)
|
249
|
-
File.
|
250
|
+
if File.exists?(filename)
|
251
|
+
time = Time.now
|
252
|
+
File.utime(time, time, filename)
|
253
|
+
else
|
254
|
+
File.open(filename, 'w'){}
|
255
|
+
end
|
250
256
|
self
|
251
257
|
end
|
252
258
|
|
data/test/tc_constants.rb
CHANGED
data/test/tc_touch.rb
CHANGED
@@ -10,7 +10,8 @@ require 'ptools'
|
|
10
10
|
class TC_FileTouch < Test::Unit::TestCase
|
11
11
|
def setup
|
12
12
|
Dir.chdir('test') unless File.basename(Dir.pwd) == 'test'
|
13
|
-
@test_file =
|
13
|
+
@test_file = 'delete.this'
|
14
|
+
@xfile = 'test_file1.txt'
|
14
15
|
end
|
15
16
|
|
16
17
|
def test_touch_basic
|
@@ -24,6 +25,14 @@ class TC_FileTouch < Test::Unit::TestCase
|
|
24
25
|
assert_equal(0, File.size(@test_file))
|
25
26
|
end
|
26
27
|
|
28
|
+
def test_touch_existing_file
|
29
|
+
stat = File.stat(@xfile)
|
30
|
+
sleep 1
|
31
|
+
assert_nothing_raised{ File.touch(@xfile) }
|
32
|
+
assert_equal(true, File.size(@xfile) == stat.size)
|
33
|
+
assert_equal(false, File.mtime(@xfile) == stat.mtime)
|
34
|
+
end
|
35
|
+
|
27
36
|
def test_touch_expected_errors
|
28
37
|
assert_raises(ArgumentError){ File.touch }
|
29
38
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: ptools
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.1.
|
7
|
-
date: 2007-
|
6
|
+
version: 1.1.6
|
7
|
+
date: 2007-08-31 00:00:00 -06:00
|
8
8
|
summary: Extra methods for the File class
|
9
9
|
require_paths:
|
10
10
|
- lib
|