ptools 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGES.md +8 -0
- data/Gemfile +1 -10
- data/lib/ptools.rb +34 -7
- data/ptools.gemspec +1 -1
- data/spec/constants_spec.rb +2 -12
- data/spec/touch_spec.rb +1 -1
- metadata +3 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36406684b5e92604183390f36512e57d842143d4f7cdc29f9f728cb8085c99f6
|
4
|
+
data.tar.gz: 736ef4ab5f6ff12ec22e4158eeb09f1a5d3db94f969ae4991ac7732fa2d4b0e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 872ba6353a2e52e845bb2b2e6b1fced1e334873b5da3edcd9764d481f4db1434b07d8b85e5e60e222e467b9ca67e36b019aac639a172c414f64398a1a29cf463
|
7
|
+
data.tar.gz: b38ac907b048d378c89807fae43e3a6d5c38e2f34b3afbfbacd333cb0860393e2be4faab59bcb0f800cb2f02f49e5110b05fc21b6a870ce2f2829560fdf1759e
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## 1.4.2 - 6-Jan-2021
|
2
|
+
* Fixed a private access modifier that wasn't actually working as intended.
|
3
|
+
* Two Windows constants that were never meant for public consumption have been marked private.
|
4
|
+
* Minor tweak to one of the touch specs.
|
5
|
+
* The Gemfile now just uses the gemspec.
|
6
|
+
* The image? singleton method was effectively ignoring filename extensions. This
|
7
|
+
has been fixed, though with the option to disable that check if desired.
|
8
|
+
|
1
9
|
## 1.4.1 - 29-Dec-2020
|
2
10
|
* Switch from rdoc to markdown since github is not rendering rdoc properly.
|
3
11
|
* Added metadata to gemspec.
|
data/Gemfile
CHANGED
data/lib/ptools.rb
CHANGED
@@ -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.4.
|
6
|
+
PTOOLS_VERSION = '1.4.2'.freeze
|
7
7
|
|
8
8
|
# :stopdoc:
|
9
9
|
|
@@ -19,17 +19,26 @@ class File
|
|
19
19
|
MSWINDOWS = false
|
20
20
|
end
|
21
21
|
|
22
|
-
|
22
|
+
if File::ALT_SEPARATOR
|
23
|
+
private_constant :WIN32EXTS
|
24
|
+
private_constant :MSWINDOWS
|
25
|
+
end
|
26
|
+
|
27
|
+
IMAGE_EXT = %w[.bmp .gif .jpg .jpeg .png .ico]
|
23
28
|
|
24
29
|
# :startdoc:
|
25
30
|
|
26
31
|
# Returns whether or not the file is an image. Only JPEG, PNG, BMP,
|
27
32
|
# GIF, and ICO are checked against.
|
28
33
|
#
|
29
|
-
# This
|
34
|
+
# This reads and checks the first few bytes of the file. For a version
|
30
35
|
# that is more robust, but which depends on a 3rd party C library (and is
|
31
36
|
# difficult to build on MS Windows), see the 'filemagic' library.
|
32
37
|
#
|
38
|
+
# By default the filename extension is also checked. You can disable this
|
39
|
+
# by passing false as the second argument, in which case only the contents
|
40
|
+
# are checked.
|
41
|
+
#
|
33
42
|
# Examples:
|
34
43
|
#
|
35
44
|
# File.image?('somefile.jpg') # => true
|
@@ -38,9 +47,13 @@ class File
|
|
38
47
|
# The approach I used here is based on information found at
|
39
48
|
# http://en.wikipedia.org/wiki/Magic_number_(programming)
|
40
49
|
#
|
41
|
-
def self.image?(file)
|
42
|
-
bool = IMAGE_EXT.include?(File.extname(file).downcase)
|
50
|
+
def self.image?(file, check_file_extension = true)
|
43
51
|
bool = bmp?(file) || jpg?(file) || png?(file) || gif?(file) || tiff?(file) || ico?(file)
|
52
|
+
|
53
|
+
if check_file_extension
|
54
|
+
bool = bool && IMAGE_EXT.include?(File.extname(file).downcase)
|
55
|
+
end
|
56
|
+
|
44
57
|
bool
|
45
58
|
end
|
46
59
|
|
@@ -402,8 +415,6 @@ class File
|
|
402
415
|
end
|
403
416
|
end
|
404
417
|
|
405
|
-
private
|
406
|
-
|
407
418
|
# Returns whether or not the given +text+ contains a BOM marker.
|
408
419
|
# If present, we can generally assume it's a text file.
|
409
420
|
#
|
@@ -418,6 +429,10 @@ class File
|
|
418
429
|
bool
|
419
430
|
end
|
420
431
|
|
432
|
+
private_class_method :check_bom?
|
433
|
+
|
434
|
+
# Returns the newline characters for the given platform.
|
435
|
+
#
|
421
436
|
def self.nl_for_platform(platform)
|
422
437
|
platform = RbConfig::CONFIG["host_os"] if platform == 'local'
|
423
438
|
|
@@ -433,22 +448,32 @@ class File
|
|
433
448
|
end
|
434
449
|
end
|
435
450
|
|
451
|
+
# Is the file a bitmap file?
|
452
|
+
#
|
436
453
|
def self.bmp?(file)
|
437
454
|
IO.read(file, 3) == "BM6"
|
438
455
|
end
|
439
456
|
|
457
|
+
# Is the file a jpeg file?
|
458
|
+
#
|
440
459
|
def self.jpg?(file)
|
441
460
|
IO.read(file, 10, nil, :encoding => 'binary') == "\377\330\377\340\000\020JFIF".force_encoding(Encoding::BINARY)
|
442
461
|
end
|
443
462
|
|
463
|
+
# Is the file a png file?
|
464
|
+
#
|
444
465
|
def self.png?(file)
|
445
466
|
IO.read(file, 4, nil, :encoding => 'binary') == "\211PNG".force_encoding(Encoding::BINARY)
|
446
467
|
end
|
447
468
|
|
469
|
+
# Is the file a gif?
|
470
|
+
#
|
448
471
|
def self.gif?(file)
|
449
472
|
['GIF89a', 'GIF97a'].include?(IO.read(file, 6))
|
450
473
|
end
|
451
474
|
|
475
|
+
# Is the file a tiff?
|
476
|
+
#
|
452
477
|
def self.tiff?(file)
|
453
478
|
return false if File.size(file) < 12
|
454
479
|
|
@@ -470,6 +495,8 @@ class File
|
|
470
495
|
true
|
471
496
|
end
|
472
497
|
|
498
|
+
# Is the file an ico file?
|
499
|
+
#
|
473
500
|
def self.ico?(file)
|
474
501
|
["\000\000\001\000", "\000\000\002\000"].include?(IO.read(file, 4, nil, :encoding => 'binary'))
|
475
502
|
end
|
data/ptools.gemspec
CHANGED
data/spec/constants_spec.rb
CHANGED
@@ -13,21 +13,11 @@ RSpec.describe File, :constants do
|
|
13
13
|
let(:windows) { File::ALT_SEPARATOR }
|
14
14
|
|
15
15
|
example "PTOOLS_VERSION constant is set to expected value" do
|
16
|
-
expect(File::PTOOLS_VERSION).to eq('1.4.
|
16
|
+
expect(File::PTOOLS_VERSION).to eq('1.4.2')
|
17
17
|
expect(File::PTOOLS_VERSION.frozen?).to be true
|
18
18
|
end
|
19
19
|
|
20
20
|
example "IMAGE_EXT constant is set to array of values" do
|
21
|
-
expect(File::IMAGE_EXT
|
22
|
-
end
|
23
|
-
|
24
|
-
example "WINDOWS constant is defined on MS Windows" do
|
25
|
-
skip "skipped unless MS Windows" unless windows
|
26
|
-
expect(File::MSWINDOWS).not_to be_nil
|
27
|
-
end
|
28
|
-
|
29
|
-
example "WIN32EXTS constant is defined on MS Windows" do
|
30
|
-
skip "skipped unless MS Windows" unless windows
|
31
|
-
expect(File::WIN32EXTS).not_to be_nil
|
21
|
+
expect(File::IMAGE_EXT).to match_array(%w[.bmp .gif .ico .jpeg .jpg .png])
|
32
22
|
end
|
33
23
|
end
|
data/spec/touch_spec.rb
CHANGED
@@ -30,7 +30,7 @@ RSpec.describe File, :touch do
|
|
30
30
|
|
31
31
|
example "touch an existing file returns expected results" do
|
32
32
|
stat = File.stat(xfile)
|
33
|
-
sleep
|
33
|
+
sleep 1
|
34
34
|
expect{ File.touch(xfile) }.not_to raise_error
|
35
35
|
expect(File.size(xfile) == stat.size).to be true
|
36
36
|
expect(File.mtime(xfile) == stat.mtime).to be false
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ptools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel J. Berger
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
|
36
36
|
WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
38
|
+
date: 2021-01-06 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: rake
|
@@ -126,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
126
|
- !ruby/object:Gem::Version
|
127
127
|
version: '0'
|
128
128
|
requirements: []
|
129
|
-
rubygems_version: 3.
|
129
|
+
rubygems_version: 3.0.3
|
130
130
|
signing_key:
|
131
131
|
specification_version: 4
|
132
132
|
summary: Extra methods for the File class
|
metadata.gz.sig
CHANGED
Binary file
|