qasa-url 0.1.2 → 0.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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -11
  3. data/lib/qasa/url/version.rb +1 -1
  4. data/lib/url.rb +27 -2
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70e637380f87112da94c4baabe3f72d117175fcf151978501057034cddee03bd
4
- data.tar.gz: e93986b23ed44518830a92af7ce6c7da5c7c096bf4a0f3de30b70dbf696e79d7
3
+ metadata.gz: da87a5058a88b4fd8f610e7950afb30f03453d7e9fe67d4c8682bad3699608a8
4
+ data.tar.gz: 5552a59d77879d045c20819031a2521df3eb5ab1c1a767b53b71a656116eaf82
5
5
  SHA512:
6
- metadata.gz: edfaad59c0df751e0b3da3420322d5d9b7be56bb0cc68b095b58fd22ade71af2ce0edfe34c351412d2ccaf640535de5bcb2c0036413c05bb8979384f438cd876
7
- data.tar.gz: b5b65f227aad9869a2c7430a90b52743b54c06ff9aeb73ad60aa2043ede1b9c4155655c8b6f6684802387fb16c919256cac4439b4f3666d3f0bc298413713190
6
+ metadata.gz: d96e2f786ca8ec0a93edf2d662e691ecf7e996d73519e5cdfea3fade2ae8bf339d56b35f7732fb8b9c90477aeb2ef00e2e53c7117a5fe6a353ab334b89978c78
7
+ data.tar.gz: 46fe970aefe8cd4d4f7e6d3c300c426e4db4ce6430b93b120f35ad70149a2aa114ca321b98b3155551278fe2aecd322e9a5da82858a5f80f281d55f5bfffdbf1
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # URL
2
- URL is a simple URL parser and construction tool for Ruby. It doesn't follow any RFC, instead, it behaves as you expect.
2
+ **URL** is a simple URL parser and construction tool for Ruby. It doesn't strictly follow any RFCs instead, **it behaves as you’d expect**.
3
3
 
4
4
  ## Background
5
- This gem was born out of frustration with the URL handling in Ruby's standard library and other gems. I wanted to be able to parse a URL, modify it and then get the modified URL back as a string. I also wanted to be able to join paths and query strings to URLs without having to worry about trailing slashes and question marks.
5
+ This gem was born out of frustration with the URL handling in Rubys standard library and other gems.
6
+ I wanted to parse a URL, modify it, and then convert it back to a string. I also wanted to join paths and query strings to URLs without worrying about trailing slashes or question marks.
6
7
 
7
8
  ## Installation
8
9
  ```ruby
@@ -11,7 +12,7 @@ gem "qasa-url"
11
12
 
12
13
  ## Usage
13
14
  ```ruby
14
- # Initialize a new URL object by parsing a URL string:
15
+ # Initialize a new URL object from a string:
15
16
  url = URL.parse("http://www.example.com:404/path")
16
17
  url.to_s # => "http://www.example.com:404/path"
17
18
 
@@ -30,21 +31,22 @@ url.to_s # => "https://www.example.com/path/to/nowhere?foo=bar"
30
31
  url = URL["example.com"]
31
32
  url.join("/path", "to", "nowhere")
32
33
 
33
- # Note: If you don't provide a protocol, it'll default to "https":
34
+ # Note: If no protocol is provided, it defaults to "https":
34
35
  url.to_s # => "https://example.com/path/to/nowhere"
35
36
  ```
36
37
 
37
- ## Alternatives
38
- If you're looking for something that parses URLs in Ruby and Ruby on Rails and closely conforms to RFC 3986, RFC 3987, and RFC 6570 (level 4),
39
- check out [addressable](https://github.com/sporkmonger/addressable).
40
- If you need to do domain name validation check out [public_suffix](https://github.com/weppos/publicsuffix-ruby).
38
+ ## Alternatives
39
+ If you're looking for something that parses URLs in Ruby and Ruby on Rails and closely conforms to RFC 3986, RFC 3987, and RFC 6570 (level 4), check out [addressable](https://github.com/sporkmonger/addressable).
40
+ For domain name validation, see [public_suffix](https://github.com/weppos/publicsuffix-ruby).
41
41
 
42
42
  ## Risks using this gem
43
- The risk should be considered low. The gem is very small, simple and well-tested. The only risk is that it doesn't follow any RFCs. This means that it might not behave as you expect. However, it's very unlikely that you'll run into any problems.
44
- The gem is maintained by [Qasa](https://www.qasa.se), we're a small team of dedicated Ruby developers.
43
+ The risks of using this gem are very low. It’s small, simple, and well-tested.
44
+ The main caveat is that it doesn’t follow any RFCs, so behavior may differ in edge cases. That said, it’s unlikely you’ll encounter issues in practice.
45
+
46
+ This gem is actively maintained by [Qasa](https://www.qasa.se), a small team of dedicated Ruby developers.
45
47
 
46
48
  ## Contributing
47
- Bug reports and pull requests are always welcome!
49
+ **Bug reports and pull requests are always welcome!**
48
50
 
49
51
  ## License
50
52
  See [LICENSE](LICENSE).
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Qasa
4
4
  module Url
5
- VERSION = "0.1.2"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
data/lib/url.rb CHANGED
@@ -139,7 +139,7 @@ class URL
139
139
  # @param path [String] a single string path
140
140
  # @overload join(*paths)
141
141
  # @param paths [Array<String>] an array of string paths
142
- # @return [URL] self
142
+ # @return [URL] duplicate of self
143
143
  # @example
144
144
  # url = URL.parse("https://www.example.com")
145
145
  # url.join("path").path("to", "nowhere")
@@ -149,6 +149,18 @@ class URL
149
149
  # url.join("/path", "/to/", "nowhere/")
150
150
  # url.to_s # => "https://www.example.com/path/to/nowhere/"
151
151
  def join(*paths)
152
+ dup = self.dup
153
+
154
+ dup.join!(*paths)
155
+ end
156
+
157
+ # Adds a path to the URL
158
+ # @overload join(path)
159
+ # @param path [String] a single string path
160
+ # @overload join(*paths)
161
+ # @param paths [Array<String>] an array of string paths
162
+ # @return [URL] self
163
+ def join!(*paths)
152
164
  parts = Array(path).concat(paths)
153
165
  size = parts.size
154
166
 
@@ -165,12 +177,25 @@ class URL
165
177
 
166
178
  # Append query parameters to the URL
167
179
  # @param [Hash]
168
- # @return [URL] self
180
+ # @return [URL] duplicate of self
169
181
  # @example
170
182
  # url = URL.parse("https://www.example.com")
171
183
  # url.merge(query: "string")
172
184
  # url.to_s # => "https://www.example.com?query=string"
173
185
  def merge(query)
186
+ dup = self.dup
187
+
188
+ dup.merge!(query)
189
+ end
190
+
191
+ # Append query parameters to the URL
192
+ # @param [Hash]
193
+ # @return [URL] self
194
+ # @example
195
+ # url = URL.parse("https://www.example.com")
196
+ # url.merge(query: "string")
197
+ # url.to_s # => "https://www.example.com?query=string"
198
+ def merge!(query)
174
199
  self.query = self.query.merge(deep_transform_keys(query))
175
200
 
176
201
  self
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qasa-url
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ingemar