protocol-url 0.16.0 → 0.17.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
  SHA256:
3
- metadata.gz: 19ab80e6eb5272f7866b22b006ff4803adefdaa8913f35a81c8f1b79b0e60de6
4
- data.tar.gz: 525c3a31f539f9250dab7a33e069785132ae7d86e0e1789e02dc1e9c0447d4c1
3
+ metadata.gz: b2aa761d6ff888e7d33270085ff84b2743230dec6a755450987a1f005b9ff124
4
+ data.tar.gz: 1de5b782218b6c8d289704d7cfc953593cf5133e86fe7c55edbda8044a9e9b41
5
5
  SHA512:
6
- metadata.gz: 272e4b1d19ae57a938e2407b77f5d2f2f8df65df57bd7651459ccb104c8d52e4d8a765a8d4a4462ea2f0b365bbd2b6bde6dfe4b77ad005caf6f3ff2910757e77
7
- data.tar.gz: 7c73a1a644c936e64c41d5c9c578dbee3b08eb9b1e735bc57ffe32b7193ef7edd43a28504ac9b8e600f1904365621059b4a2dd9f7398c81c897da925e7741a18
6
+ metadata.gz: 58533d06cadb21b1f038b156a7bb7d0d0e39c503e8993bab5fd7c7811d2f03e13b8431aa97b5221e925cbabdbb75b1d0a95d58d57c5c29d701aa552c327c0568
7
+ data.tar.gz: 5fce5dc33f50136790eff38c7a122e7041c0b06fa07ce2b1bfc41ade0568f352a731b26b233c9aa36b2d7ce460a0b1de32dfd9b68beed86213c123d5bd5676d8
checksums.yaml.gz.sig CHANGED
Binary file
@@ -147,8 +147,9 @@ module Protocol
147
147
 
148
148
  # Absolute URLs cannot be made relative without comparing their origins.
149
149
  # @parameter base [Object] The ignored base URL or path.
150
+ # @parameter explicit [Boolean] Ignored for absolute URLs.
150
151
  # @returns [self] This absolute URL.
151
- def relative_to(base)
152
+ def relative_to(base, explicit: false)
152
153
  return self
153
154
  end
154
155
 
@@ -67,6 +67,7 @@ module Protocol
67
67
  #
68
68
  # @parameter target [String] The destination path (where you want to go).
69
69
  # @parameter from [String] The source path (where you are starting from).
70
+ # @parameter explicit [Boolean] Whether same-directory paths should start with `./`.
70
71
  # @returns [String] The relative path from `from` to `target`.
71
72
  #
72
73
  # @example Calculate relative path between pages.
@@ -76,8 +77,8 @@ module Protocol
76
77
  # @example Calculate relative path in same directory.
77
78
  # Path.relative("/docs/guide.html", "/docs/index.html")
78
79
  # # => "guide.html"
79
- def self.relative(target, from)
80
- return Path[target].relative(from).to_s
80
+ def self.relative(target, from, explicit: false)
81
+ return Path[target].relative(from, explicit: explicit).to_s
81
82
  end
82
83
 
83
84
  # Initialize a path from either its complete encoded representation or encoded segments.
@@ -357,8 +358,9 @@ module Protocol
357
358
  # Calculate this path relative to another path.
358
359
  #
359
360
  # @parameter from [String | Array(String) | Path] The source path.
361
+ # @parameter explicit [Boolean] Whether same-directory paths should start with `./`.
360
362
  # @returns [Path] The relative path from `from` to this path.
361
- def relative(from)
363
+ def relative(from, explicit: false)
362
364
  target_segments = self.segments
363
365
  from_segments = Path[from].segments
364
366
 
@@ -386,6 +388,9 @@ module Protocol
386
388
  # An empty reference identifies the current document, so identify the current directory explicitly:
387
389
  if relative_segments == [""]
388
390
  relative_segments = [".", ""]
391
+ elsif explicit && relative_segments.first != ".."
392
+ # Identify same-directory references explicitly:
393
+ relative_segments.unshift(".")
389
394
  elsif relative_segments.first&.include?(":")
390
395
  # A colon in the first segment would be interpreted as a URI scheme:
391
396
  relative_segments.unshift(".")
@@ -138,15 +138,16 @@ module Protocol
138
138
  # are preserved when converting a root-relative path.
139
139
  #
140
140
  # @parameter base [Relative | Path | String] The base URL or path.
141
+ # @parameter explicit [Boolean] Whether same-directory paths should start with `./`.
141
142
  # @returns [Relative] The relative URL.
142
- def relative_to(base)
143
+ def relative_to(base, explicit: false)
143
144
  return self unless @path.absolute?
144
145
 
145
146
  if base.is_a?(Relative)
146
147
  base = base.path
147
148
  end
148
149
 
149
- return self.class.new(@path.relative(base), @query, @fragment)
150
+ return self.class.new(@path.relative(base, explicit: explicit), @query, @fragment)
150
151
  end
151
152
 
152
153
  # Normalize the encoded path and simplify its structure.
@@ -7,6 +7,6 @@
7
7
  module Protocol
8
8
  # @namespace
9
9
  module URL
10
- VERSION = "0.16.0"
10
+ VERSION = "0.17.0"
11
11
  end
12
12
  end
data/readme.md CHANGED
@@ -34,6 +34,46 @@ bundle exec sus
34
34
 
35
35
  Please see the [project releases](https://socketry.github.io/protocol-url/releases/index) for all releases.
36
36
 
37
+ ### v0.17.0
38
+
39
+ - Add optional explicit `./` prefixes when generating same-directory relative URLs.
40
+
41
+ ### v0.16.0
42
+
43
+ - Preserve directory and file semantics when generating relative URL paths.
44
+
45
+ ### v0.15.0
46
+
47
+ - Add `Protocol::URL::Relative#relative_to` for expressing root-relative URLs relative to a base path.
48
+
49
+ ### v0.14.0
50
+
51
+ - Allow paths to compare with their encoded string representation.
52
+
53
+ ### v0.13.0
54
+
55
+ - Add conservative normalization of encoded URL paths.
56
+
57
+ ### v0.12.0
58
+
59
+ - Allow unfrozen relative and absolute URLs to replace their components.
60
+
61
+ ### v0.10.0
62
+
63
+ - Rename `Protocol::URL::FormData::Parser::CONTENT_TYPE` to `MEDIA_TYPE`.
64
+
65
+ ### v0.9.0
66
+
67
+ - Add `Protocol::URL::LimitError` for configured processing limits.
68
+
69
+ ### v0.8.0
70
+
71
+ - Use consistent limit naming for form data parser constraints.
72
+
73
+ ### v0.7.0
74
+
75
+ - Allow `Protocol::URL::FormData::Parser#parse` to populate a supplied result object.
76
+
37
77
  ### v0.16.0
38
78
 
39
79
  - Preserve directory and file semantics when generating relative URL paths.
data/releases.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Releases
2
2
 
3
+ ## v0.17.0
4
+
5
+ - Add optional explicit `./` prefixes when generating same-directory relative URLs.
6
+
3
7
  ## v0.16.0
4
8
 
5
9
  - Preserve directory and file semantics when generating relative URL paths.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol-url
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
metadata.gz.sig CHANGED
Binary file