file-uri 1.1.0 → 1.2.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
2
  SHA1:
3
- metadata.gz: 3525f546d39d44784846b1f02a372cf6bb78b555
4
- data.tar.gz: e23b88aa0f6bfa10d88c9fc29c15466c1c37ec48
3
+ metadata.gz: 54ee4ae8cbd94f94495f686a8fcd6b76b8b2582b
4
+ data.tar.gz: b1011ec0178af3d464cbf3fe13e7dc7c79ba2cb4
5
5
  SHA512:
6
- metadata.gz: 9ae089e1b4a47e938587b75300a43a334fb9df07c1b292373960ad4928d3990106229fe27daba337de6a3787c4500e7d9c3d21ef6dad9989e9aa4def13ada888
7
- data.tar.gz: b66d19dfa6aa6025d46990af64fa1f178151d1ea4942648f41e190b7188b387fa0bf6f54936e60bd2039bd15e1286e898df1c176d8deda4909e744ac8ca09b80
6
+ metadata.gz: 71d1065ba4be44fddb18c0df6ad7fe7e28cdf60c326eb02501e6ae0ff55288555f7842e51716511383b4c7246be1424ee2352c0c701183a7e590ca50d527e029
7
+ data.tar.gz: 4f9e8018087902fbb3790d098a51648abba23b048471a3b5213ca9527b3b76fce97d13bc0cb06c363bd5ac00c0bd7e61ae3fae8286b938ec007a97c2e5e381dc
@@ -1,5 +1,5 @@
1
1
  require 'uri/generic'
2
- require_relative 'file-uri-common'
2
+ require_relative 'file-uri/common'
3
3
 
4
4
  module URI
5
5
  class CoreFile < Generic
@@ -19,11 +19,13 @@ module URI
19
19
  ##
20
20
  # localhost:
21
21
  #
22
+ # * :any => any non-empty host is local
22
23
  # * true => 'file://localhost/' is local, 'file://example.com/' is non-local
23
24
  # * false => 'file://localhost/' is non-local
24
25
  #
25
26
  def local? localhost: true
26
27
  if host && !host.empty?
28
+ return true if localhost == :any
27
29
  return localhost && (host.downcase == LOCALHOST)
28
30
  elsif path.start_with? DBL_SLASH
29
31
  return false
@@ -34,6 +36,7 @@ module URI
34
36
  ##
35
37
  # localhost:
36
38
  #
39
+ # * :any => any non-empty host is local
37
40
  # * true => 'file://localhost/' is local, 'file://example.com/' is non-local
38
41
  # * false => 'file://localhost/' is non-local
39
42
  #
@@ -45,12 +48,13 @@ module URI
45
48
  ##
46
49
  # localhost:
47
50
  #
51
+ # * :any => any non-empty host is local
48
52
  # * true => 'file://localhost/' is local, 'file://example.com/' is non-local
49
53
  # * false => 'file://localhost/' is non-local
50
54
  #
51
55
  def to_unc localhost: true
52
56
  if host && !host.empty?
53
- unless localhost && (host.downcase == LOCALHOST)
57
+ if localhost != :any && (!localhost || (host.downcase != LOCALHOST))
54
58
  unc = DBL_BACKSLASH + host
55
59
  unc += COLON + port if port
56
60
  unc += path.gsub(%r[/], BACKSLASH)
@@ -1,7 +1,7 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  require 'uri/generic'
4
- require_relative '../file-uri-common'
4
+ require_relative 'common'
5
5
 
6
6
  module URI
7
7
  class WinFile < Generic
@@ -37,14 +37,17 @@ class Test_file_uri < Test::Unit::TestCase
37
37
  assert_equal( false, uri.local?(localhost: false) )
38
38
  assert_equal( false, uri.local?(localhost: true) )
39
39
  assert_equal( false, uri.local? )
40
+ assert_equal( false, uri.local?(localhost: :any) )
40
41
 
41
42
  assert_raise(RuntimeError) { uri.to_file_path(localhost: false) }
42
43
  assert_raise(RuntimeError) { uri.to_file_path(localhost: true) }
43
44
  assert_raise(RuntimeError) { uri.to_file_path }
45
+ assert_raise(RuntimeError) { uri.to_file_path(localhost: :any) }
44
46
 
45
47
  assert_equal( unc, uri.to_unc(localhost: false) )
46
48
  assert_equal( unc, uri.to_unc(localhost: true) )
47
49
  assert_equal( unc, uri.to_unc )
50
+ assert_equal( unc, uri.to_unc(localhost: :any) )
48
51
  end
49
52
  end
50
53
 
@@ -62,14 +65,17 @@ class Test_file_uri < Test::Unit::TestCase
62
65
  assert_equal( false, uri.local?(localhost: false) )
63
66
  assert_equal( false, uri.local?(localhost: true) )
64
67
  assert_equal( false, uri.local? )
68
+ assert_equal( true, uri.local?(localhost: :any) )
65
69
 
66
70
  assert_raise(RuntimeError) { uri.to_file_path(localhost: false) }
67
71
  assert_raise(RuntimeError) { uri.to_file_path(localhost: true) }
68
72
  assert_raise(RuntimeError) { uri.to_file_path }
73
+ assert_equal( path, uri.to_file_path(localhost: :any) )
69
74
 
70
75
  assert_equal( unc, uri.to_unc(localhost: false) )
71
76
  assert_equal( unc, uri.to_unc(localhost: true) )
72
77
  assert_equal( unc, uri.to_unc )
78
+ assert_raise(RuntimeError) { uri.to_unc(localhost: :any) }
73
79
  end
74
80
  end
75
81
 
@@ -86,14 +92,17 @@ class Test_file_uri < Test::Unit::TestCase
86
92
  assert_equal( false, uri.local?(localhost: false) )
87
93
  assert_equal( true, uri.local?(localhost: true) )
88
94
  assert_equal( true, uri.local? )
95
+ assert_equal( true, uri.local?(localhost: :any) )
89
96
 
90
97
  assert_raise(RuntimeError) { uri.to_file_path(localhost: false) }
91
98
  assert_equal( path, uri.to_file_path(localhost: true) )
92
99
  assert_equal( path, uri.to_file_path )
100
+ assert_equal( path, uri.to_file_path(localhost: :any) )
93
101
 
94
102
  assert_equal( unc, uri.to_unc(localhost: false) )
95
103
  assert_raise(RuntimeError) { uri.to_unc(localhost: true) }
96
104
  assert_raise(RuntimeError) { uri.to_unc }
105
+ assert_raise(RuntimeError) { uri.to_unc(localhost: :any) }
97
106
  end
98
107
  end
99
108
 
@@ -49,14 +49,17 @@ class Test_win_file_uri < Test::Unit::TestCase
49
49
  assert_equal( false, uri.local?(localhost: false) )
50
50
  assert_equal( false, uri.local?(localhost: true) )
51
51
  assert_equal( false, uri.local? )
52
+ assert_equal( false, uri.local?(localhost: :any) )
52
53
 
53
54
  assert_raise(RuntimeError) { uri.to_file_path(localhost: false) }
54
55
  assert_raise(RuntimeError) { uri.to_file_path(localhost: true) }
55
56
  assert_raise(RuntimeError) { uri.to_file_path }
57
+ assert_raise(RuntimeError) { uri.to_file_path(localhost: :any) }
56
58
 
57
59
  assert_equal( unc, uri.to_unc(localhost: false) )
58
60
  assert_equal( unc, uri.to_unc(localhost: true) )
59
61
  assert_equal( unc, uri.to_unc )
62
+ assert_equal( unc, uri.to_unc(localhost: :any) )
60
63
  end
61
64
  end
62
65
 
@@ -74,14 +77,17 @@ class Test_win_file_uri < Test::Unit::TestCase
74
77
  assert_equal( false, uri.local?(localhost: false) )
75
78
  assert_equal( false, uri.local?(localhost: true) )
76
79
  assert_equal( false, uri.local? )
80
+ assert_equal( true, uri.local?(localhost: :any) )
77
81
 
78
82
  assert_raise(RuntimeError) { uri.to_file_path(localhost: false) }
79
83
  assert_raise(RuntimeError) { uri.to_file_path(localhost: true) }
80
84
  assert_raise(RuntimeError) { uri.to_file_path }
85
+ assert_equal( path, uri.to_file_path(localhost: :any) )
81
86
 
82
87
  assert_equal( unc, uri.to_unc(localhost: false) )
83
88
  assert_equal( unc, uri.to_unc(localhost: true) )
84
89
  assert_equal( unc, uri.to_unc )
90
+ assert_raise(RuntimeError) { uri.to_unc(localhost: :any) }
85
91
  end
86
92
  end
87
93
 
@@ -100,14 +106,17 @@ class Test_win_file_uri < Test::Unit::TestCase
100
106
  assert_equal( false, uri.local?(localhost: false) )
101
107
  assert_equal( true, uri.local?(localhost: true) )
102
108
  assert_equal( true, uri.local? )
109
+ assert_equal( true, uri.local?(localhost: :any) )
103
110
 
104
111
  assert_raise(RuntimeError) { uri.to_file_path(localhost: false) }
105
112
  assert_equal( file, uri.to_file_path(localhost: true) )
106
113
  assert_equal( file, uri.to_file_path )
114
+ assert_equal( file, uri.to_file_path(localhost: :any) )
107
115
 
108
116
  assert_equal( unc, uri.to_unc(localhost: false) )
109
117
  assert_raise(RuntimeError) { uri.to_unc(localhost: true) }
110
118
  assert_raise(RuntimeError) { uri.to_unc }
119
+ assert_raise(RuntimeError) { uri.to_unc(localhost: :any) }
111
120
  end
112
121
  end
113
122
 
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.1.0
4
+ version: 1.2.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-08 00:00:00.000000000 Z
11
+ date: 2016-12-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  == file-uri – the "file" URI Scheme
@@ -22,8 +22,8 @@ executables: []
22
22
  extensions: []
23
23
  extra_rdoc_files: []
24
24
  files:
25
- - lib/file-uri-common.rb
26
25
  - lib/file-uri.rb
26
+ - lib/file-uri/common.rb
27
27
  - lib/file-uri/win.rb
28
28
  - test/test-file-uri.rb
29
29
  - test/test-win-file-uri.rb