furi 0.2.3 → 0.2.5

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: 37ea1203ca474e34d99624eb7e7cf43935197a4cec1a0a49e110b8674f5a1cec
4
- data.tar.gz: 5ef6f167bd64ac72f6a8b78324c871a88734f06e39faecd4e7aaee1abe5a2f0a
3
+ metadata.gz: 60584a8bc9851e0f203430c73a18b5b4c4d22c25484134caf8f256279203ed7e
4
+ data.tar.gz: ee1258bc6788c8d11bf8f5c7a48dced7c5338ad36409de0a3eb049c194cd3347
5
5
  SHA512:
6
- metadata.gz: db8b15ea5e9d25852df4be4e83a67bf60d8ed85d703fba1fa7a1ee28fbe7d2e547dc4ea182d52ef396316f92ef3634264750b4d76d0016c51c6a9afe78b19e11
7
- data.tar.gz: 9617142f8e989e885c8bd17a874fa221b6df1f2bea1398a786e9291f4d87d9d6ae4913f8904c3273902b8c0a1d008b0ec3f0aa8918aef34d9d5538fca93a0861
6
+ metadata.gz: 161c291815412a22f32a2c6e6e8b32fc74241eba6e44442197f1a04d2c934522898014e8e7c6b0cc53c396f0a95076a193e23dd41a8abf38ea0b976058b76d00
7
+ data.tar.gz: ac25ee7829104064cde493e5310a7302d08593808f56674bc4cce7af4e1d6e5be3504300cd396d79276abe5a6153be52084613af8a7679d30fbc1afa2f007912
data/CHANGELOG.md CHANGED
@@ -1,3 +1,27 @@
1
+ # v0.2.4
2
+
3
+ * Improved `Furi.update` behavior for `path:` overrides:
4
+
5
+ * Supports **relative path resolution** (`..` and subpaths)
6
+ * Leading slashes in `path` now **replace** the original path
7
+ * `nil` path removes the path portion entirely, leaving only the host
8
+
9
+ **Examples:**
10
+
11
+ ```ruby
12
+ Furi.update("https://www.google.com/maps", path: "place/1.23,3.28")
13
+ # => "https://www.google.com/maps/place/1.23,3.28"
14
+
15
+ Furi.update("https://www.google.com/maps", path: "/account")
16
+ # => "https://www.google.com/account"
17
+
18
+ Furi.update("https://www.google.com/maps", path: "..")
19
+ # => "https://www.google.com/"
20
+
21
+ Furi.update("https://www.google.com/maps", path: nil)
22
+ # => "https://www.google.com"
23
+ ```
24
+
1
25
  # v0.2.3
2
26
 
3
27
  * Ruby 3.0 support #2
data/README.md CHANGED
@@ -58,6 +58,20 @@ Building an URI from initial parts:
58
58
  ``` ruby
59
59
  Furi.build(protocol: '//', host: 'gusiev.com', path: '/assets/application.js')
60
60
  # => "//gusiev.com/assets/application.js"
61
+
62
+ Furi.build(
63
+ location: 'https://calendar.google.com',
64
+ path: '/calendar/render',
65
+ query: {
66
+ action: 'TEMPLATE',
67
+ text: 'Seven Figure Club Meeting',
68
+ dates: [Time.now + 2.hours, Time.now + 3.hours].map do |t|
69
+ t.strftime("%Y%m%dT%H%M%SZ")
70
+ end.join('/'),
71
+ details: 'Seven Figure Club invites to the discussion with other founders to one of the topics you have expressed your interest to.',
72
+ add: ["bogdan@example.com", "brad@example.com"].join(',')
73
+ }
74
+ )
61
75
  ```
62
76
 
63
77
  ### Working with Object
data/lib/furi/uri.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'pathname'
2
+
1
3
  module Furi
2
4
  class Uri
3
5
 
@@ -44,6 +46,12 @@ module Furi
44
46
  case part.to_sym
45
47
  when :query, :query_tokens, :query_string
46
48
  merge_query(value)
49
+ when :path
50
+ if value && self[part]
51
+ self[part] = Pathname.new(self[part]).join(value).to_s
52
+ else
53
+ self[part] = value
54
+ end
47
55
  else
48
56
  self[part] = value
49
57
  end
@@ -72,7 +80,10 @@ module Furi
72
80
  def merge_query(query)
73
81
  case query
74
82
  when Hash
75
- self.query = self.query.merge(Furi::Utils.stringify_keys(query))
83
+ self.query = Furi::Utils.deep_merge(
84
+ self.query,
85
+ Furi::Utils.stringify_keys(query)
86
+ )
76
87
  when String, Array
77
88
  self.query_tokens += Furi.query_tokens(query)
78
89
  when nil
@@ -238,10 +249,8 @@ module Furi
238
249
  query
239
250
  when String, Array
240
251
  self.query_tokens = value
241
- @query = nil
242
252
  when Hash
243
253
  self.query_tokens = value
244
- @query = value
245
254
  when nil
246
255
  else
247
256
  raise QueryParseError, 'Query can only be Hash or String'
@@ -273,7 +282,7 @@ module Furi
273
282
  end
274
283
 
275
284
  def query_tokens=(tokens)
276
- @query = nil
285
+ @query = tokens.is_a?(Hash) ? tokens : nil
277
286
  @query_tokens = Furi.query_tokens(tokens)
278
287
  end
279
288
 
data/lib/furi/utils.rb CHANGED
@@ -10,7 +10,17 @@ module Furi
10
10
  end
11
11
  result
12
12
  end
13
+
14
+ def deep_merge(current_hash, other_hash)
15
+ current_hash.merge(other_hash) do |key, this_val, other_val|
16
+ if this_val.is_a?(Hash) && other_val.is_a?(Hash)
17
+ deep_merge(this_val, other_val)
18
+ else
19
+ other_val
20
+ end
21
+ end
22
+ end
13
23
  end
14
24
  end
15
25
  end
16
-
26
+
data/lib/furi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Furi
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: furi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdan Gusiev
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2021-04-05 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: The philosophy of this gem is to make any URI modification or parsing
14
13
  operation to take only one line of code and never more
@@ -39,7 +38,6 @@ metadata:
39
38
  allowed_push_host: https://rubygems.org
40
39
  homepage_uri: https://github.com/bogdan/furi
41
40
  source_code_uri: https://github.com/bogdan/furi
42
- post_install_message:
43
41
  rdoc_options: []
44
42
  require_paths:
45
43
  - lib
@@ -54,8 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
52
  - !ruby/object:Gem::Version
55
53
  version: '0'
56
54
  requirements: []
57
- rubygems_version: 3.2.0
58
- signing_key:
55
+ rubygems_version: 3.6.7
59
56
  specification_version: 4
60
57
  summary: Make URI processing as easy as it should be
61
58
  test_files: []