file-uri 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/file-uri.rb +1 -1
- data/lib/file-uri/common.rb +11 -1
- data/lib/file-uri/win.rb +1 -1
- data/test/test-file-uri.rb +23 -5
- data/test/test-win-file-uri.rb +5 -5
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0d537ba0d3f1ad8625553e3c475ca2d49f3d270cec59f0974e446f8af67e9db3
|
4
|
+
data.tar.gz: 30df84986a3f81dd4bb5091540176e613a1bdce9732341990dc9b915328423c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e556520f46523bbd45c7033b60aac060182bede9dc35daca4f90481a4ff97ec4d76c9d43f40ecbc812e3904ddc0fca8225c93cf2964e7d60e37bdee42505506d
|
7
|
+
data.tar.gz: 744329508030c1c422be8ecff4b2ff3b1a23320ea6165cc86e4a65f6804210f4fd91ddf5a9b04daecf3fa486326061e2702b3b9c4189bc3caf5a3ad49f2d86a0
|
data/lib/file-uri.rb
CHANGED
data/lib/file-uri/common.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'uri/generic'
|
2
2
|
|
3
3
|
module URI
|
4
|
-
module
|
4
|
+
module FileCommon
|
5
5
|
|
6
6
|
COMPONENT = %i[
|
7
7
|
scheme
|
@@ -66,6 +66,16 @@ module URI
|
|
66
66
|
raise "no UNC conversion for local URI #{to_s}"
|
67
67
|
end
|
68
68
|
|
69
|
+
##
|
70
|
+
# open( [mode [, perm]] [, opt]) --> io or nil
|
71
|
+
# open( [mode [, perm]] [, opt]) {|io| block } --> obj
|
72
|
+
#
|
73
|
+
# See Kernel#open, URI::File#to_file_path
|
74
|
+
#
|
75
|
+
def open *args, localhost: :true, &block
|
76
|
+
Kernel::open to_file_path(localhost: localhost), *args, &block
|
77
|
+
end
|
78
|
+
|
69
79
|
COLON = ?:.freeze
|
70
80
|
SLASH = ?/.freeze
|
71
81
|
DBL_SLASH = '//'.freeze
|
data/lib/file-uri/win.rb
CHANGED
data/test/test-file-uri.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
require 'test/unit'
|
3
|
+
require 'tempfile'
|
2
4
|
$VERBOSE = true
|
3
5
|
|
4
6
|
|
@@ -12,9 +14,9 @@ class Test_file_uri < Test::Unit::TestCase
|
|
12
14
|
['file:/short/path/to/file', '/short/path/to/file'],
|
13
15
|
].each do |str, path|
|
14
16
|
uri = URI.parse(str)
|
15
|
-
assert_kind_of( URI::
|
17
|
+
assert_kind_of( URI::FileCommon, uri )
|
16
18
|
assert_equal( path, uri.path )
|
17
|
-
# these depend on it being a URI::
|
19
|
+
# these depend on it being a URI::FileCommon object
|
18
20
|
assert_equal( true, uri.local? )
|
19
21
|
assert_equal( path, uri.to_file_path )
|
20
22
|
end
|
@@ -31,7 +33,7 @@ class Test_file_uri < Test::Unit::TestCase
|
|
31
33
|
['file://///localhost/Share/dir/file.ext', '//localhost/Share/dir/file.ext', '\\\\localhost\\Share\\dir\\file.ext'],
|
32
34
|
].each do |str, path, unc|
|
33
35
|
uri = URI.parse(str)
|
34
|
-
assert_kind_of( URI::
|
36
|
+
assert_kind_of( URI::FileCommon, uri )
|
35
37
|
assert_equal( path, uri.path )
|
36
38
|
|
37
39
|
assert_equal( false, uri.local?(localhost: false) )
|
@@ -58,7 +60,7 @@ class Test_file_uri < Test::Unit::TestCase
|
|
58
60
|
['file://example.com/Share/dir/file.ext', 'example.com', '/Share/dir/file.ext', '\\\\example.com\\Share\\dir\\file.ext'],
|
59
61
|
].each do |str, host, path, unc|
|
60
62
|
uri = URI.parse(str)
|
61
|
-
assert_kind_of( URI::
|
63
|
+
assert_kind_of( URI::FileCommon, uri )
|
62
64
|
assert_equal( path, uri.path )
|
63
65
|
assert_equal( host, uri.host )
|
64
66
|
|
@@ -86,7 +88,7 @@ class Test_file_uri < Test::Unit::TestCase
|
|
86
88
|
['file://localhost/path/to/file', '/path/to/file', '\\\\localhost\\path\\to\\file'],
|
87
89
|
].each do |str, path, unc|
|
88
90
|
uri = URI.parse(str)
|
89
|
-
assert_kind_of( URI::
|
91
|
+
assert_kind_of( URI::FileCommon, uri )
|
90
92
|
assert_equal( path, uri.path )
|
91
93
|
|
92
94
|
assert_equal( false, uri.local?(localhost: false) )
|
@@ -106,4 +108,20 @@ class Test_file_uri < Test::Unit::TestCase
|
|
106
108
|
end
|
107
109
|
end
|
108
110
|
|
111
|
+
def test_open
|
112
|
+
input = "abcde"
|
113
|
+
tmp = Tempfile.new('file-uri')
|
114
|
+
begin
|
115
|
+
path = tmp.path
|
116
|
+
tmp.write(input)
|
117
|
+
tmp.close
|
118
|
+
|
119
|
+
uri = URI.parse('file:' + path)
|
120
|
+
assert_kind_of( URI::FileCommon, uri )
|
121
|
+
assert_equal( input, uri.open('r') {|io| io.read } )
|
122
|
+
ensure
|
123
|
+
tmp.unlink
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
109
127
|
end
|
data/test/test-win-file-uri.rb
CHANGED
@@ -24,9 +24,9 @@ class Test_win_file_uri < Test::Unit::TestCase
|
|
24
24
|
['file:///c:/path:to/file', '/c:/path:to/file', "c:/path\u{F03A}to/file"],
|
25
25
|
].each do |str, path, file|
|
26
26
|
uri = URI.parse(str)
|
27
|
-
assert_kind_of( URI::
|
27
|
+
assert_kind_of( URI::FileCommon, uri )
|
28
28
|
assert_equal( path, uri.path )
|
29
|
-
# these depend on it being a URI::
|
29
|
+
# these depend on it being a URI::FileCommon object
|
30
30
|
assert_equal( true, uri.local? )
|
31
31
|
assert_equal( file, uri.to_file_path )
|
32
32
|
end
|
@@ -43,7 +43,7 @@ class Test_win_file_uri < Test::Unit::TestCase
|
|
43
43
|
['file://///localhost/Share/dir/file.ext', '//localhost/Share/dir/file.ext', '\\\\localhost\\Share\\dir\\file.ext'],
|
44
44
|
].each do |str, path, unc|
|
45
45
|
uri = URI.parse(str)
|
46
|
-
assert_kind_of( URI::
|
46
|
+
assert_kind_of( URI::FileCommon, uri )
|
47
47
|
assert_equal( path, uri.path )
|
48
48
|
|
49
49
|
assert_equal( false, uri.local?(localhost: false) )
|
@@ -70,7 +70,7 @@ class Test_win_file_uri < Test::Unit::TestCase
|
|
70
70
|
['file://example.com/Share/dir/file.ext', 'example.com', '/Share/dir/file.ext', '\\\\example.com\\Share\\dir\\file.ext'],
|
71
71
|
].each do |str, host, path, unc|
|
72
72
|
uri = URI.parse(str)
|
73
|
-
assert_kind_of( URI::
|
73
|
+
assert_kind_of( URI::FileCommon, uri )
|
74
74
|
assert_equal( path, uri.path )
|
75
75
|
assert_equal( host, uri.host )
|
76
76
|
|
@@ -100,7 +100,7 @@ class Test_win_file_uri < Test::Unit::TestCase
|
|
100
100
|
['file://localhost/path/to:file', '/path/to:file', '\\\\localhost\\path\\to:file', "/path/to\u{F03A}file"],
|
101
101
|
].each do |str, path, unc, file|
|
102
102
|
uri = URI.parse(str)
|
103
|
-
assert_kind_of( URI::
|
103
|
+
assert_kind_of( URI::FileCommon, uri )
|
104
104
|
assert_equal( path, uri.path )
|
105
105
|
|
106
106
|
assert_equal( false, uri.local?(localhost: false) )
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: file-uri
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Kerwin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
== file-uri – the "file" URI Scheme
|
@@ -46,8 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
requirements: []
|
49
|
-
|
50
|
-
rubygems_version: 2.6.7
|
49
|
+
rubygems_version: 3.0.1
|
51
50
|
signing_key:
|
52
51
|
specification_version: 4
|
53
52
|
summary: file-uri – the "file" URI Scheme
|