file-uri 1.2.0 → 1.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 54ee4ae8cbd94f94495f686a8fcd6b76b8b2582b
4
- data.tar.gz: b1011ec0178af3d464cbf3fe13e7dc7c79ba2cb4
2
+ SHA256:
3
+ metadata.gz: 0d537ba0d3f1ad8625553e3c475ca2d49f3d270cec59f0974e446f8af67e9db3
4
+ data.tar.gz: 30df84986a3f81dd4bb5091540176e613a1bdce9732341990dc9b915328423c3
5
5
  SHA512:
6
- metadata.gz: 71d1065ba4be44fddb18c0df6ad7fe7e28cdf60c326eb02501e6ae0ff55288555f7842e51716511383b4c7246be1424ee2352c0c701183a7e590ca50d527e029
7
- data.tar.gz: 4f9e8018087902fbb3790d098a51648abba23b048471a3b5213ca9527b3b76fce97d13bc0cb06c363bd5ac00c0bd7e61ae3fae8286b938ec007a97c2e5e381dc
6
+ metadata.gz: e556520f46523bbd45c7033b60aac060182bede9dc35daca4f90481a4ff97ec4d76c9d43f40ecbc812e3904ddc0fca8225c93cf2964e7d60e37bdee42505506d
7
+ data.tar.gz: 744329508030c1c422be8ecff4b2ff3b1a23320ea6165cc86e4a65f6804210f4fd91ddf5a9b04daecf3fa486326061e2702b3b9c4189bc3caf5a3ad49f2d86a0
data/lib/file-uri.rb CHANGED
@@ -3,7 +3,7 @@ require_relative 'file-uri/common'
3
3
 
4
4
  module URI
5
5
  class CoreFile < Generic
6
- include File
6
+ include FileCommon
7
7
 
8
8
  def initialize(scheme,
9
9
  userinfo, host, port, registry,
@@ -1,7 +1,7 @@
1
1
  require 'uri/generic'
2
2
 
3
3
  module URI
4
- module File
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
@@ -5,7 +5,7 @@ require_relative 'common'
5
5
 
6
6
  module URI
7
7
  class WinFile < Generic
8
- include File
8
+ include FileCommon
9
9
 
10
10
  def fixup path
11
11
  path.gsub(%r[\A/([A-Z]):?(?=/|\z)]i, '/\1:')
@@ -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::File, uri )
17
+ assert_kind_of( URI::FileCommon, uri )
16
18
  assert_equal( path, uri.path )
17
- # these depend on it being a URI::File object
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::File, 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::File, 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::File, 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
@@ -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::File, uri )
27
+ assert_kind_of( URI::FileCommon, uri )
28
28
  assert_equal( path, uri.path )
29
- # these depend on it being a URI::File object
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::File, 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::File, 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::File, 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.2.0
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: 2016-12-15 00:00:00.000000000 Z
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
- rubyforge_project:
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