ptools 1.3.1-universal-mingw32 → 1.3.7-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YTI0ODIwZjk4NGU5MmY2M2FkYTk3OWM4MzgwYzc0NWJmNTlhOWRjMw==
5
- data.tar.gz: !binary |-
6
- NDU1MTE1YmU3ZGFkYjc2ZWY5NmQyY2VjODQ4ZWUxNjQwMmM2ODlkNg==
2
+ SHA256:
3
+ metadata.gz: 69b0c5a7f01036c4e8b29773fcda191482ec37cef11ed835d77e84d6d1113e09
4
+ data.tar.gz: 6acb8b4b8b4a0bc479d912bbf9f8eae991725f6a766f6c1c85c2149b771a1dfc
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- OWZlYWMyNDFlYTRkM2Q0ZGVmZWRmMmI2M2Q1OWNiNjdiNjRhOGI5ODc4NGM2
10
- YTkwNTM1YWUyYTQxZTQ2YzQ1MDYwYmMzZjJjMjAzMGJlN2JiMDg0YmNkMzVl
11
- NmViOTNjMTgzYjk1ZDg1NDU3MTUzNDgxOTllZjQ5N2IwNDcwN2M=
12
- data.tar.gz: !binary |-
13
- NWE4OTllMDVlYTUyOTM4NzAzN2Y0NjRhYzFiMzUxNzMzYzQ3MDE1NzA0YzQz
14
- NzAxZTQ1OTJkOTAzZWE2ZTMzMDgxNDlmZmM0ZTc2ZjQxMjZjMDU1Y2E0NGU4
15
- Yzg0OWJlZmJmNTk5MmU5MDcxOTM5Y2FjNGI0ODAyMjQ2ZjdhMDc=
6
+ metadata.gz: 8bed3889606d6351aa7c2a636be91c3a17a05470516355db715a9fa2f88f5d3cf7442771938cd70c2a796e26eb1f5c04a87e03d007793fffcfbed09175178bd1
7
+ data.tar.gz: 793779b97fdd26452c6066ba7416d770a6d02e4c862e0637c40531c374955c54507616b466916f4d1130022f7f2f363e5c377c0cd673bfd9f63cd9c7e2cee5ce
Binary file
Binary file
data/CHANGES CHANGED
@@ -1,3 +1,37 @@
1
+ == 1.3.7 - 24-Jun-2020
2
+ * Fixed a bug where the File.binary? method would bomb on a zero byte file.
3
+ Thanks go to Alexandru Emil Lupu for the spot and patch.
4
+ * Remove Gemfile.lock from repo. You can generate that yourself locally if
5
+ you want.
6
+
7
+ == 1.3.6 - 7-Jun-2020
8
+ * Updated gemspec, added more versions to .travis.yml file, fixed typo.
9
+ Thanks go to Al Snow for the updates.
10
+ * Fixed a bug where the File.binary? method would return true for utf16
11
+ or utf32 encoded files. Thanks go to Andrew McAndre for the spot.
12
+ * Updated cert.
13
+
14
+ == 1.3.5 - 3-Sep-2017
15
+ * The File.image? method now checks against .ico files.
16
+ * Eliminated Fixnum warning that showed up in Ruby 2.4.x.
17
+ * Updated cert.
18
+
19
+ == 1.3.4 - 4-Jul-2017
20
+ * The File.binary? method now lets you set your own percentage for the
21
+ internal heuristic as an optional second argument.
22
+ * The VERSION constant is now frozen.
23
+ * Minor updates to the Rakefile and gemspec.
24
+ * Updated cert file.
25
+
26
+ == 1.3.3 - 25-Sep-2015
27
+ * This gem is now signed.
28
+ * The Rakefile tasks now assume Rubygems 2.x.
29
+
30
+ == 1.3.2 - 11-Dec-2014
31
+ * Update to the File.tail method that deals prevents potential line ending
32
+ issues in JRuby.
33
+ * Added known issues with JRuby to the README.
34
+
1
35
  == 1.3.1 - 9-Dec-2014
2
36
  * Fixed some potential issues with File.tail. Thanks go to Matt Hoyle for
3
37
  the patch.
data/MANIFEST CHANGED
@@ -1,8 +1,10 @@
1
1
  * CHANGES
2
2
  * README
3
3
  * MANIFEST
4
+ * Gemfile
4
5
  * Rakefile
5
6
  * ptools.gemspec
7
+ * certs/djberg96_pub.pem
6
8
  * lib/ptools.rb
7
9
  * test/test_constants.rb
8
10
  * test/test_head.rb
@@ -17,3 +19,4 @@
17
19
  * test/img/test.gif
18
20
  * test/img/test.jpg
19
21
  * test/img/test.png
22
+ * test/img/test.ico
data/README CHANGED
@@ -3,7 +3,7 @@
3
3
  File class based on Unix command line tools.
4
4
 
5
5
  == Prerequisites
6
- On MS Windows you will need win32-file 0.5.4 or later.
6
+ On MS Windows you will need the win32-file gem.
7
7
 
8
8
  == Installation
9
9
  gem install ptools
@@ -27,7 +27,10 @@
27
27
  File.nl_convert("myfile", "newfile", "dos")
28
28
 
29
29
  == Known Bugs
30
- None known. Please report any bugs on the github project page.
30
+ The File.which and File.whereis methods may fail when using JRuby on Windows.
31
+ See https://github.com/jruby/jruby/issues/2291 for details.
32
+
33
+ Please report any other issues on the github project page.
31
34
 
32
35
  http://www.github.com/djberg96/ptools
33
36
 
@@ -42,6 +45,10 @@
42
45
  The binary?() method was based almost entirely on a blog post by Ryan
43
46
  Davis (who, in turn, based his code on Perl's -B switch).
44
47
 
48
+ Thanks go to Matt Hoyle for help with the File.tail method.
49
+
50
+ And thanks to any and all contributors!
51
+
45
52
  == Future Plans
46
53
  Add whatever other tools people think might be useful.
47
54
 
@@ -49,7 +56,7 @@
49
56
  Artistic 2.0
50
57
 
51
58
  == Copyright
52
- (C) 2003-2014 Daniel J. Berger
59
+ (C) 2003-2020 Daniel J. Berger
53
60
  All Rights Reserved.
54
61
 
55
62
  == Warranty
data/Rakefile CHANGED
@@ -8,28 +8,28 @@ CLEAN.include("**/*.gem", "**/*.rbc", "**/*coverage*")
8
8
 
9
9
  desc 'Install the ptools package (non-gem)'
10
10
  task :install do
11
- sitelibdir = CONFIG["sitelibdir"]
12
- file = "lib/ptools.rb"
13
- FileUtils.cp(file, sitelibdir, :verbose => true)
11
+ sitelibdir = CONFIG["sitelibdir"]
12
+ file = "lib/ptools.rb"
13
+ FileUtils.cp(file, sitelibdir, :verbose => true)
14
14
  end
15
15
 
16
16
  namespace 'gem' do
17
17
  desc 'Create the ptools gem'
18
18
  task :create => [:clean] do
19
- Dir["*.gem"].each{ |f| File.delete(f) } # Clean first
19
+ require 'rubygems/package'
20
20
  spec = eval(IO.read('ptools.gemspec'))
21
- if Gem::VERSION < "2.0.0"
22
- Gem::Builder.new(spec).build
23
- else
24
- require 'rubygems/package'
25
- Gem::Package.build(spec)
26
- end
21
+ spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
22
+ Gem::Package.build(spec, true)
27
23
  end
28
24
 
29
25
  desc 'Install the ptools gem'
30
26
  task :install => [:create] do
31
27
  file = Dir["*.gem"].first
32
- sh "gem install -l #{file}"
28
+ if RUBY_PLATFORM == 'java'
29
+ sh "jruby -S gem install -l #{file}"
30
+ else
31
+ sh "gem install -l #{file}"
32
+ end
33
33
  end
34
34
  end
35
35
 
@@ -75,13 +75,6 @@ namespace 'test' do
75
75
  t.test_files = FileList['test/test_image.rb']
76
76
  end
77
77
 
78
- Rake::TestTask.new('middle') do |t|
79
- t.libs << 'test'
80
- t.verbose = true
81
- t.warning = true
82
- t.test_files = FileList['test/test_middle.rb']
83
- end
84
-
85
78
  Rake::TestTask.new('nlconvert') do |t|
86
79
  t.libs << 'test'
87
80
  t.verbose = true
@@ -0,0 +1,26 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIEcDCCAtigAwIBAgIBATANBgkqhkiG9w0BAQsFADA/MREwDwYDVQQDDAhkamJl
3
+ cmc5NjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
4
+ MB4XDTE4MDMxODE1MjIwN1oXDTI4MDMxNTE1MjIwN1owPzERMA8GA1UEAwwIZGpi
5
+ ZXJnOTYxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
6
+ bTCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBALgfaroVM6CI06cxr0/h
7
+ A+j+pc8fgpRgBVmHFaFunq28GPC3IvW7Nvc3Y8SnAW7pP1EQIbhlwRIaQzJ93/yj
8
+ u95KpkP7tA9erypnV7dpzBkzNlX14ACaFD/6pHoXoe2ltBxk3CCyyzx70mTqJpph
9
+ 75IB03ni9a8yqn8pmse+s83bFJOAqddSj009sG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s4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
26
+ -----END CERTIFICATE-----
@@ -3,7 +3,7 @@ require 'win32/file' if File::ALT_SEPARATOR
3
3
 
4
4
  class File
5
5
  # The version of the ptools library.
6
- PTOOLS_VERSION = '1.3.1'
6
+ PTOOLS_VERSION = '1.3.7'.freeze
7
7
 
8
8
  # :stopdoc:
9
9
 
@@ -23,8 +23,8 @@ class File
23
23
 
24
24
  # :startdoc:
25
25
 
26
- # Returns whether or not the file is an image. Only JPEG, PNG, BMP and
27
- # GIF are checked against.
26
+ # Returns whether or not the file is an image. Only JPEG, PNG, BMP,
27
+ # GIF, and ICO are checked against.
28
28
  #
29
29
  # This method does some simple read and extension checks. For a version
30
30
  # that is more robust, but which depends on a 3rd party C library (and is
@@ -39,8 +39,8 @@ class File
39
39
  # http://en.wikipedia.org/wiki/Magic_number_(programming)
40
40
  #
41
41
  def self.image?(file)
42
- bool = IMAGE_EXT.include?(File.extname(file).downcase) # Match ext
43
- bool = bmp?(file) || jpg?(file) || png?(file) || gif?(file) || tiff?(file) # Check data
42
+ bool = IMAGE_EXT.include?(File.extname(file).downcase)
43
+ bool = bmp?(file) || jpg?(file) || png?(file) || gif?(file) || tiff?(file) || ico?(file)
44
44
  bool
45
45
  end
46
46
 
@@ -79,6 +79,10 @@ class File
79
79
  # It performs a "best guess" based on a simple test of the first
80
80
  # +File.blksize+ characters, or 4096, whichever is smaller.
81
81
  #
82
+ # By default it will check to see if more than 30 percent of the characters
83
+ # are non-text characters. If so, the method returns true. You can configure
84
+ # this percentage by passing your own as a second argument.
85
+ #
82
86
  # Example:
83
87
  #
84
88
  # File.binary?('somefile.exe') # => true
@@ -87,13 +91,15 @@ class File
87
91
  # Based on code originally provided by Ryan Davis (which, in turn, is
88
92
  # based on Perl's -B switch).
89
93
  #
90
- def self.binary?(file)
94
+ def self.binary?(file, percentage = 0.30)
95
+ return false if File.stat(file).zero?
91
96
  return false if image?(file)
97
+ return false if check_bom?(file)
92
98
  bytes = File.stat(file).blksize
93
99
  bytes = 4096 if bytes > 4096
94
100
  s = (File.read(file, bytes) || "")
95
101
  s = s.encode('US-ASCII', :undef => :replace).split(//)
96
- ((s.size - s.grep(" ".."~").size) / s.size.to_f) > 0.30
102
+ ((s.size - s.grep(" ".."~").size) / s.size.to_f) > percentage
97
103
  end
98
104
 
99
105
  # Looks for the first occurrence of +program+ within +path+.
@@ -247,6 +253,10 @@ class File
247
253
  # If you're looking for tail -f functionality, please use the file-tail
248
254
  # gem instead.
249
255
  #
256
+ #--
257
+ # Internally I'm using a 64 chunk of memory at a time. I may allow the size
258
+ # to be configured in the future as an optional 3rd argument.
259
+ #
250
260
  def self.tail(filename, num_lines=10)
251
261
  tail_size = 2**16 # 64k chunks
252
262
 
@@ -255,24 +265,26 @@ class File
255
265
  file_size = File.size(filename)
256
266
  read_bytes = file_size % tail_size
257
267
  read_bytes = tail_size if read_bytes == 0
258
- line_sep = File::ALT_SEPARATOR ? "\r\n" : "\n"
268
+
269
+ line_sep = File::ALT_SEPARATOR ? "\r\n" : "\n"
259
270
 
260
271
  buf = ''
261
272
 
262
- File.open(filename){ |fh|
263
- # Set the starting read position
264
- position = file_size - read_bytes
265
-
273
+ # Open in binary mode to ensure line endings aren't converted.
274
+ File.open(filename, 'rb'){ |fh|
275
+ position = file_size - read_bytes # Set the starting read position
276
+
266
277
  # Loop until we have the lines or run out of file
267
278
  while buf.scan(line_sep).size <= num_lines and position >= 0
268
279
  fh.seek(position, IO::SEEK_SET)
269
280
  buf = fh.read(read_bytes) + buf
270
281
  read_bytes = tail_size
271
- position -= read_bytes
282
+ position -= read_bytes
272
283
  end
273
284
  }
274
285
 
275
286
  lines = buf.split(line_sep).pop(num_lines)
287
+
276
288
  if block_given?
277
289
  lines.each{ |line| yield line }
278
290
  else
@@ -422,6 +434,20 @@ class File
422
434
 
423
435
  private
424
436
 
437
+ # Returns whether or not the given +text+ contains a BOM marker.
438
+ # If present, we can generally assume it's a text file.
439
+ #
440
+ def self.check_bom?(file)
441
+ text = File.read(file, 4).force_encoding('utf-8')
442
+
443
+ bool = false
444
+ bool = true if text[0,3] == "\xEF\xBB\xBF"
445
+ bool = true if text[0,4] == "\x00\x00\xFE\xFF" || text[0,4] == "\xFF\xFE\x00\x00"
446
+ bool = true if text[0,2] == "\xFF\xFE" || text[0,2] == "\xFE\xFF"
447
+
448
+ bool
449
+ end
450
+
425
451
  def self.nl_for_platform(platform)
426
452
  platform = RbConfig::CONFIG["host_os"] if platform == 'local'
427
453
 
@@ -473,4 +499,8 @@ class File
473
499
 
474
500
  true
475
501
  end
502
+
503
+ def self.ico?(file)
504
+ ["\000\000\001\000", "\000\000\002\000"].include?(IO.read(file, 4, nil, :encoding => 'binary'))
505
+ end
476
506
  end
@@ -1,30 +1,30 @@
1
- require 'rubygems'
2
1
  require 'rbconfig'
3
2
 
4
- Gem::Specification.new do |gem|
5
- gem.name = 'ptools'
6
- gem.version = '1.3.1'
7
- gem.license = 'Artistic 2.0'
8
- gem.author = 'Daniel J. Berger'
9
- gem.email = 'djberg96@gmail.com'
10
- gem.homepage = 'https://github.com/djberg96/ptools'
11
- gem.summary = 'Extra methods for the File class'
12
- gem.test_files = Dir['test/test*']
13
- gem.files = Dir['**/*'] << '.gemtest'
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'ptools'
5
+ spec.version = '1.3.7'
6
+ spec.license = 'Artistic-2.0'
7
+ spec.author = 'Daniel J. Berger'
8
+ spec.email = 'djberg96@gmail.com'
9
+ spec.homepage = 'https://github.com/djberg96/ptools'
10
+ spec.summary = 'Extra methods for the File class'
11
+ spec.test_files = Dir['test/test*']
12
+ spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
13
+ spec.cert_chain = ['certs/djberg96_pub.pem']
14
14
 
15
- gem.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
15
+ spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
16
16
 
17
- gem.description = <<-EOF
17
+ spec.description = <<-EOF
18
18
  The ptools (power tools) library provides several handy methods to
19
19
  Ruby's core File class, such as File.which for finding executables,
20
20
  File.null to return the null device on your platform, and so on.
21
21
  EOF
22
22
 
23
- gem.add_development_dependency('rake')
24
- gem.add_development_dependency('test-unit', '>= 2.5.0')
23
+ spec.add_development_dependency('rake')
24
+ spec.add_development_dependency('test-unit')
25
25
 
26
26
  if File::ALT_SEPARATOR
27
- gem.platform = Gem::Platform.new(['universal', 'mingw32'])
28
- gem.add_dependency('win32-file', '>= 0.7.0')
27
+ spec.platform = Gem::Platform.new(['universal', 'mingw32'])
28
+ spec.add_dependency('win32-file')
29
29
  end
30
30
  end
Binary file
@@ -16,15 +16,17 @@ class TC_Ptools_Binary < Test::Unit::TestCase
16
16
  @@bin_file = '/bin/ls'
17
17
  end
18
18
 
19
- Dir.chdir('test') if File.exist?('test')
19
+ @@dirname = File.dirname(__FILE__)
20
20
  end
21
21
 
22
22
  def setup
23
- @txt_file = File.join('txt', 'english.txt')
24
- @uni_file = File.join('txt', 'korean.txt')
25
- @png_file = File.join('img', 'test.png')
26
- @jpg_file = File.join('img', 'test.jpg')
27
- @gif_file = File.join('img', 'test.gif')
23
+ @txt_file = File.join(@@dirname, 'txt', 'english.txt')
24
+ @emp_file = File.join(@@dirname, 'txt', 'empty.txt')
25
+ @uni_file = File.join(@@dirname, 'txt', 'korean.txt')
26
+ @utf_file = File.join(@@dirname, 'txt', 'english.utf16')
27
+ @png_file = File.join(@@dirname, 'img', 'test.png')
28
+ @jpg_file = File.join(@@dirname, 'img', 'test.jpg')
29
+ @gif_file = File.join(@@dirname, 'img', 'test.gif')
28
30
  end
29
31
 
30
32
  test "File.binary? basic functionality" do
@@ -37,8 +39,10 @@ class TC_Ptools_Binary < Test::Unit::TestCase
37
39
  end
38
40
 
39
41
  test "File.binary? returns false for text files" do
42
+ assert_false(File.binary?(@emp_file))
40
43
  assert_false(File.binary?(@txt_file))
41
44
  assert_false(File.binary?(@uni_file))
45
+ assert_false(File.binary?(@utf_file))
42
46
  end
43
47
 
44
48
  test "File.binary? returns false for image files" do
@@ -47,6 +51,11 @@ class TC_Ptools_Binary < Test::Unit::TestCase
47
51
  assert_false(File.binary?(@gif_file))
48
52
  end
49
53
 
54
+ test "File.binary? accepts an optional percentage argument" do
55
+ assert_false(File.binary?(@txt_file, 0.50))
56
+ assert_true(File.binary?(@txt_file, 0.05))
57
+ end
58
+
50
59
  test "File.binary? raises an error if the file cannot be found" do
51
60
  assert_raise_kind_of(SystemCallError){ File.binary?('bogus') }
52
61
  end
@@ -15,7 +15,8 @@ class TC_Ptools_Constants < Test::Unit::TestCase
15
15
  end
16
16
 
17
17
  test "PTOOLS_VERSION constant is set to expected value" do
18
- assert_equal('1.3.1', File::PTOOLS_VERSION)
18
+ assert_equal('1.3.7', File::PTOOLS_VERSION)
19
+ assert_true(File::PTOOLS_VERSION.frozen?)
19
20
  end
20
21
 
21
22
  test "IMAGE_EXT constant is set to array of values" do
@@ -27,7 +28,7 @@ class TC_Ptools_Constants < Test::Unit::TestCase
27
28
  assert_not_nil(File::MSWINDOWS)
28
29
  end
29
30
 
30
- test "WIN32EXTS constant is defiend on MS Windows" do
31
+ test "WIN32EXTS constant is defined on MS Windows" do
31
32
  omit_unless(@@windows, "Skipping on Unix systems")
32
33
  assert_not_nil(File::WIN32EXTS)
33
34
  end
@@ -18,6 +18,7 @@ class TC_Ptools_Image < Test::Unit::TestCase
18
18
  @jpg_file = File.join(Dir.pwd, 'img', 'test.jpg')
19
19
  @png_file = File.join(Dir.pwd, 'img', 'test.png')
20
20
  @gif_file = File.join(Dir.pwd, 'img', 'test.gif')
21
+ @ico_file = File.join(Dir.pwd, 'img', 'test.ico')
21
22
  end
22
23
 
23
24
  test "image? method basic functionality" do
@@ -43,6 +44,10 @@ class TC_Ptools_Image < Test::Unit::TestCase
43
44
  assert_true(File.image?(@png_file))
44
45
  end
45
46
 
47
+ test "image? method returns true for an ico" do
48
+ assert_true(File.image?(@ico_file))
49
+ end
50
+
46
51
  test "image? method raises an error if the file does not exist" do
47
52
  assert_raises(Errno::ENOENT, ArgumentError){ File.image?('bogus') }
48
53
  end
@@ -10,18 +10,18 @@ require 'ptools'
10
10
 
11
11
  class TC_Ptools_NLConvert < Test::Unit::TestCase
12
12
  def self.startup
13
- Dir.chdir('test') if File.exist?('test')
14
- @@test_file1 = 'test_nl_convert1.txt'
15
- @@test_file2 = 'test_nl_convert2.txt'
13
+ @@dirname = File.dirname(__FILE__)
14
+ @@test_file1 = File.join(@@dirname, 'test_nl_convert1.txt')
15
+ @@test_file2 = File.join(@@dirname, 'test_nl_convert2.txt')
16
16
  File.open(@@test_file1, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
17
17
  File.open(@@test_file2, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
18
18
  end
19
19
 
20
20
  def setup
21
- @test_file1 = 'test_nl_convert1.txt'
22
- @test_file2 = 'test_nl_convert2.txt'
23
- @dos_file = 'dos_test_file.txt'
24
- @mac_file = 'mac_test_file.txt'
21
+ @test_file1 = File.join(@@dirname, 'test_nl_convert1.txt')
22
+ @test_file2 = File.join(@@dirname, 'test_nl_convert2.txt')
23
+ @dos_file = File.join(@@dirname, 'dos_test_file.txt')
24
+ @mac_file = File.join(@@dirname, 'mac_test_file.txt')
25
25
  @unix_file = 'nix_test_file.txt'
26
26
  end
27
27
 
@@ -35,7 +35,7 @@ class TC_Ptools_NLConvert < Test::Unit::TestCase
35
35
  assert_equal( "\cM", File.nl_for_platform('mac') )
36
36
  assert_nothing_raised{ File.nl_for_platform('local') }
37
37
  end
38
-
38
+
39
39
  test "nl_convert basic functionality" do
40
40
  assert_respond_to(File, :nl_convert)
41
41
  end
@@ -9,48 +9,53 @@ require 'ptools'
9
9
 
10
10
  class TC_FileTail < Test::Unit::TestCase
11
11
  def self.startup
12
+ @@dirname = File.dirname(__FILE__)
12
13
 
13
- Dir.chdir('test') if File.exist?('test')
14
+ @@test_file1 = File.join(@@dirname, 'test_file1.txt')
15
+ @@test_file64 = File.join(@@dirname, 'test_file64.txt')
16
+ @@test_file128 = File.join(@@dirname, 'test_file128.txt')
14
17
 
15
- File.open('test_file1.txt', 'w'){ |fh|
18
+ @@test_file_trail = File.join(@@dirname, 'test_file_trail.txt')
19
+ @@test_file_trail_nl = File.join(@@dirname, 'test_file_trail_nl.txt')
20
+
21
+ File.open(@@test_file1, 'w'){ |fh|
16
22
  25.times{ |n| fh.puts "line#{n+1}" }
17
23
  }
18
24
 
19
25
  # Trailing newline test
20
- File.open('test_file_trail.txt', 'w'){ |fh|
26
+ File.open(@@test_file_trail, 'w'){ |fh|
21
27
  2.times{ |n| fh.puts "trail#{n+1}" }
22
28
  fh.write "trail3"
23
29
  }
24
- File.open('test_file_trail_nl.txt', 'w'){ |fh|
30
+ File.open(@@test_file_trail_nl, 'w'){ |fh|
25
31
  3.times{ |n| fh.puts "trail#{n+1}" }
26
32
  }
27
33
 
28
34
  # Larger files
29
35
  test_tail_fmt_str = "line data data data data data data data %5s"
30
36
 
31
- File.open('test_file64.txt', 'w'){ |fh|
32
- 2000.times{ |n|
33
- fh.puts test_tail_fmt_str % (n+1).to_s
37
+ File.open(@@test_file64, 'w'){ |fh|
38
+ 2000.times{ |n|
39
+ fh.puts test_tail_fmt_str % (n+1).to_s
34
40
  }
35
41
  }
36
42
 
37
- File.open('test_file128.txt', 'w'){ |fh|
38
- 4500.times{ |n|
43
+ File.open(@@test_file128, 'w'){ |fh|
44
+ 4500.times{ |n|
39
45
  fh.puts test_tail_fmt_str % (n+1).to_s
40
46
  }
41
-
42
47
  }
43
48
  end
44
49
 
45
50
  def setup
46
- @test_file = 'test_file1.txt'
47
- @test_trail = 'test_file_trail.txt'
48
- @test_trail_nl = 'test_file_trail_nl.txt'
49
- @test_file_64 = 'test_file64.txt'
50
- @test_file_128 = 'test_file128.txt'
51
+ @test_file = @@test_file1
52
+ @test_trail = @@test_file_trail
53
+ @test_trail_nl = @@test_file_trail_nl
54
+ @test_file_64 = @@test_file64
55
+ @test_file_128 = @@test_file128
51
56
 
52
57
  @expected_tail1 = %w{
53
- line16 line17 line18 line19 line20
58
+ line16 line17 line18 line19 line20
54
59
  line21 line22 line23 line24 line25
55
60
  }
56
61
 
@@ -62,8 +67,6 @@ class TC_FileTail < Test::Unit::TestCase
62
67
  @expected_tail_trail = %w{ trail2 trail3 }
63
68
 
64
69
  @test_tail_fmt_str = "line data data data data data data data %5s"
65
-
66
-
67
70
  end
68
71
 
69
72
  def test_tail_basic
@@ -105,8 +108,6 @@ class TC_FileTail < Test::Unit::TestCase
105
108
  assert_equal( expected_tail_128k, File.tail(@test_file_128, 4500) )
106
109
  end
107
110
 
108
-
109
-
110
111
  def teardown
111
112
  @test_file = nil
112
113
  @expected_tail1 = nil
@@ -114,10 +115,10 @@ class TC_FileTail < Test::Unit::TestCase
114
115
  end
115
116
 
116
117
  def self.shutdown
117
- File.delete('test_file1.txt') if File.exist?('test_file1.txt')
118
- File.delete('test_file64.txt') if File.exist?('test_file64.txt')
119
- File.delete('test_file128.txt') if File.exist?('test_file128.txt')
120
- File.delete('test_file_trail_nl.txt') if File.exist?('test_file_trail_nl.txt')
121
- File.delete('test_file_trail.txt') if File.exist?('test_file_trail.txt')
118
+ File.delete(@@test_file1) if File.exist?(@@test_file1)
119
+ File.delete(@@test_file64) if File.exist?(@@test_file64)
120
+ File.delete(@@test_file128) if File.exist?(@@test_file128)
121
+ File.delete(@@test_file_trail_nl) if File.exist?(@@test_file_trail_nl)
122
+ File.delete(@@test_file_trail) if File.exist?(@@test_file_trail)
122
123
  end
123
124
  end
@@ -9,13 +9,14 @@ require 'ptools'
9
9
 
10
10
  class TC_FileTouch < Test::Unit::TestCase
11
11
  def self.startup
12
- Dir.chdir('test') if File.exist?('test')
13
- File.open('test_file1.txt', 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
12
+ @@dirname = File.dirname(__FILE__)
13
+ @@xfile = File.join(@@dirname, 'test_file1.txt')
14
+ File.open(@@xfile, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
14
15
  end
15
16
 
16
17
  def setup
17
- @test_file = 'delete.this'
18
- @xfile = 'test_file1.txt'
18
+ @test_file = File.join(@@dirname, 'delete.this')
19
+ @xfile = File.join(@@dirname, 'test_file1.txt')
19
20
  end
20
21
 
21
22
  def test_touch_basic
@@ -47,6 +48,6 @@ class TC_FileTouch < Test::Unit::TestCase
47
48
  end
48
49
 
49
50
  def self.shutdown
50
- File.delete('test_file1.txt') if File.exist?('test_file1.txt')
51
+ File.delete(@@xfile) if File.exist?(@@xfile)
51
52
  end
52
53
  end
File without changes
Binary file
metadata CHANGED
@@ -1,60 +1,88 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ptools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.7
5
5
  platform: universal-mingw32
6
6
  authors:
7
7
  - Daniel J. Berger
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain: []
11
- date: 2014-12-09 00:00:00.000000000 Z
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEcDCCAtigAwIBAgIBATANBgkqhkiG9w0BAQsFADA/MREwDwYDVQQDDAhkamJl
14
+ cmc5NjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
15
+ MB4XDTE4MDMxODE1MjIwN1oXDTI4MDMxNTE1MjIwN1owPzERMA8GA1UEAwwIZGpi
16
+ ZXJnOTYxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
17
+ bTCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBALgfaroVM6CI06cxr0/h
18
+ A+j+pc8fgpRgBVmHFaFunq28GPC3IvW7Nvc3Y8SnAW7pP1EQIbhlwRIaQzJ93/yj
19
+ u95KpkP7tA9erypnV7dpzBkzNlX14ACaFD/6pHoXoe2ltBxk3CCyyzx70mTqJpph
20
+ 75IB03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UP7K3Nl9oTjJNv+7/jM
36
+ WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
37
+ -----END CERTIFICATE-----
38
+ date:
12
39
  dependencies:
13
40
  - !ruby/object:Gem::Dependency
14
41
  name: rake
15
42
  requirement: !ruby/object:Gem::Requirement
16
43
  requirements:
17
- - - ! '>='
44
+ - - ">="
18
45
  - !ruby/object:Gem::Version
19
46
  version: '0'
20
47
  type: :development
21
48
  prerelease: false
22
49
  version_requirements: !ruby/object:Gem::Requirement
23
50
  requirements:
24
- - - ! '>='
51
+ - - ">="
25
52
  - !ruby/object:Gem::Version
26
53
  version: '0'
27
54
  - !ruby/object:Gem::Dependency
28
55
  name: test-unit
29
56
  requirement: !ruby/object:Gem::Requirement
30
57
  requirements:
31
- - - ! '>='
58
+ - - ">="
32
59
  - !ruby/object:Gem::Version
33
- version: 2.5.0
60
+ version: '0'
34
61
  type: :development
35
62
  prerelease: false
36
63
  version_requirements: !ruby/object:Gem::Requirement
37
64
  requirements:
38
- - - ! '>='
65
+ - - ">="
39
66
  - !ruby/object:Gem::Version
40
- version: 2.5.0
67
+ version: '0'
41
68
  - !ruby/object:Gem::Dependency
42
69
  name: win32-file
43
70
  requirement: !ruby/object:Gem::Requirement
44
71
  requirements:
45
- - - ! '>='
72
+ - - ">="
46
73
  - !ruby/object:Gem::Version
47
- version: 0.7.0
74
+ version: '0'
48
75
  type: :runtime
49
76
  prerelease: false
50
77
  version_requirements: !ruby/object:Gem::Requirement
51
78
  requirements:
52
- - - ! '>='
79
+ - - ">="
53
80
  - !ruby/object:Gem::Version
54
- version: 0.7.0
55
- description: ! " The ptools (power tools) library provides several handy methods
56
- to\n Ruby's core File class, such as File.which for finding executables,\n File.null
57
- to return the null device on your platform, and so on.\n"
81
+ version: '0'
82
+ description: |2
83
+ The ptools (power tools) library provides several handy methods to
84
+ Ruby's core File class, such as File.which for finding executables,
85
+ File.null to return the null device on your platform, and so on.
58
86
  email: djberg96@gmail.com
59
87
  executables: []
60
88
  extensions: []
@@ -63,15 +91,20 @@ extra_rdoc_files:
63
91
  - CHANGES
64
92
  - MANIFEST
65
93
  files:
66
- - .gemtest
94
+ - certs
95
+ - certs/djberg96_pub.pem
67
96
  - CHANGES
68
97
  - Gemfile
69
- - MANIFEST
70
- - README
71
- - Rakefile
98
+ - lib
72
99
  - lib/ptools.rb
100
+ - MANIFEST
73
101
  - ptools.gemspec
102
+ - Rakefile
103
+ - README
104
+ - test
105
+ - test/img
74
106
  - test/img/test.gif
107
+ - test/img/test.ico
75
108
  - test/img/test.jpg
76
109
  - test/img/test.png
77
110
  - test/test_binary.rb
@@ -86,11 +119,14 @@ files:
86
119
  - test/test_wc.rb
87
120
  - test/test_whereis.rb
88
121
  - test/test_which.rb
122
+ - test/txt
123
+ - test/txt/empty.txt
89
124
  - test/txt/english.txt
125
+ - test/txt/english.utf16
90
126
  - test/txt/korean.txt
91
127
  homepage: https://github.com/djberg96/ptools
92
128
  licenses:
93
- - Artistic 2.0
129
+ - Artistic-2.0
94
130
  metadata: {}
95
131
  post_install_message:
96
132
  rdoc_options: []
@@ -98,17 +134,16 @@ require_paths:
98
134
  - lib
99
135
  required_ruby_version: !ruby/object:Gem::Requirement
100
136
  requirements:
101
- - - ! '>='
137
+ - - ">="
102
138
  - !ruby/object:Gem::Version
103
139
  version: '0'
104
140
  required_rubygems_version: !ruby/object:Gem::Requirement
105
141
  requirements:
106
- - - ! '>='
142
+ - - ">="
107
143
  - !ruby/object:Gem::Version
108
144
  version: '0'
109
145
  requirements: []
110
- rubyforge_project:
111
- rubygems_version: 2.4.2
146
+ rubygems_version: 3.0.3
112
147
  signing_key:
113
148
  specification_version: 4
114
149
  summary: Extra methods for the File class
Binary file