tiny_gid 0.0.2 → 0.0.3

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/Changes +8 -0
  3. data/README.md +16 -0
  4. data/lib/tiny_gid.rb +13 -7
  5. metadata +7 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bbfe56b82c1febf13d59f7af4f34d6b6dd990fda2778589017aea0cf3014974c
4
- data.tar.gz: 32b4292c06d7f134b97130b32b23fb0ffb39c15bcaaea450c48b20cb6e2e65a3
3
+ metadata.gz: 90c32039e2d334d95e380dfcb236d92835f8f47206c32a7a6c618a92043bb5dd
4
+ data.tar.gz: 1179c6460da059639cada21299af8aeec2363ec0e8baf66b9ba1b8a82521cba4
5
5
  SHA512:
6
- metadata.gz: 601f57d44f7c1faacdd86d7a07fbe10bf0edf39dd3e303cc457a859168512e0bc2bb35ab426e27254dc5917b974d2791e918229b0ff3c294d5825c14363f0421
7
- data.tar.gz: bd62bc67c7182fdbaa0a51703e28ae2af914199e0938c904d7a39e0e5ae0b1ad446b5dc37171d00c4d8fda89c2310c1b8443c9bb9f324f793a786718fa8dd18d
6
+ metadata.gz: 2b2c322cd031586cd4d6aa7b82bcfc876d834b2b7301f3cd077890f28e245c274c20b5b2b5479030d7ddaeee29e8da1d96b2549b45035ed109f0c219d10f0654
7
+ data.tar.gz: e64c77cf0ce216c784bbaaf01768832e75763067e8824ebeb506610df3c46df99087d5bc077a6dae9634667dbee0fff09f2759946a196371f47f3deafadf6e3c
data/Changes ADDED
@@ -0,0 +1,8 @@
1
+ v0.0.3 2025-12-25
2
+ --------------------
3
+ Add TinyGID.parse
4
+ Add TinyGID.to_sc
5
+
6
+ v0.0.2 2025-12-11
7
+ --------------------
8
+ Make gid.app block form thread-safe
data/README.md CHANGED
@@ -53,6 +53,22 @@ gid = TinyGID.new("shopify")
53
53
  gid.Product(123)
54
54
  ```
55
55
 
56
+ ### Parsing
57
+
58
+ ```rb
59
+ app, model, id = gid.parse("gid://shopify/Product/123")
60
+ app, model, id, params = gid.parse("gid://shopify/Product/123?foo=bar")
61
+ ```
62
+
63
+ `params` is a `Hash`
64
+
65
+ If you just want the scalar ID:
66
+
67
+ ```rb
68
+ id = gid.to_sc("gid://shopify/Product/123") # "123"
69
+ id = gid.to_sc("gid://shopify/Product/123?foo=bar") # "123"
70
+ ```
71
+
56
72
  ## Why Not Use GlobalID‽
57
73
 
58
74
  [GlobalID](https://github.com/rails/globalid) is nice but it primarily deals with IDs backed by an instance of a class, e.g. Rails model, whereas
data/lib/tiny_gid.rb CHANGED
@@ -3,8 +3,9 @@
3
3
  require "uri"
4
4
 
5
5
  module TinyGID
6
- VERSION = "0.0.2"
6
+ VERSION = "0.0.3"
7
7
  FORMAT = "gid://%s/%s/%s"
8
+ REGEX = %r{\Agid://([^/]+)/([^/]+)/([^/?]+)(?:\?(.*?))?\z}
8
9
 
9
10
  module MethodMissing # :nodoc:
10
11
  def method_missing(name, *arguments, &block)
@@ -62,12 +63,17 @@ module TinyGID
62
63
  end
63
64
  end
64
65
 
65
- # Necessary?
66
- # def to_sc(gid)
67
- # # TODO:
68
- # # value, params = TinyGID.to_sc("gid://shopify/Product/123?is_a=headache")
69
- # gid.to_s.split("/")[-1]
70
- # end
66
+ def parse(gid)
67
+ raise ArgumentError, "'#{gid}' is not a valid global id" unless gid =~ REGEX
68
+
69
+ parsed = [$1, $2, $3]
70
+ parsed << Hash[URI.decode_www_form($4)] if $4 && !$4.empty?
71
+ parsed
72
+ end
73
+
74
+ def to_sc(gid)
75
+ parse(gid)[2]
76
+ end
71
77
  end
72
78
 
73
79
  def initialize(app)
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiny_gid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Skye Shaw
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 2025-12-11 00:00:00.000000000 Z
11
+ date: 2025-12-26 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: rspec
@@ -59,6 +60,7 @@ executables: []
59
60
  extensions: []
60
61
  extra_rdoc_files: []
61
62
  files:
63
+ - Changes
62
64
  - LICENSE.txt
63
65
  - README.md
64
66
  - Rakefile
@@ -71,6 +73,7 @@ licenses:
71
73
  metadata:
72
74
  homepage_uri: https://github.com/sshaw/tiny_gid
73
75
  source_code_uri: https://github.com/sshaw/tiny_gid
76
+ post_install_message:
74
77
  rdoc_options: []
75
78
  require_paths:
76
79
  - lib
@@ -85,7 +88,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
88
  - !ruby/object:Gem::Version
86
89
  version: '0'
87
90
  requirements: []
88
- rubygems_version: 3.6.2
91
+ rubygems_version: 3.5.16
92
+ signing_key:
89
93
  specification_version: 4
90
94
  summary: Tiny class to build Global ID (gid://) strings from scalar values
91
95
  test_files: []