tiny_gid 0.0.2 → 0.1.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/Changes +12 -0
  3. data/README.md +16 -0
  4. data/lib/tiny_gid.rb +14 -8
  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: 130f3c30c294915e45b4e64855cb034edc093deebd77ffdad98211a662660f55
4
+ data.tar.gz: 06d162d16c28dd28909678ce9460a0ec9eaac623f5b3d3271effbfbb6bd3922a
5
5
  SHA512:
6
- metadata.gz: 601f57d44f7c1faacdd86d7a07fbe10bf0edf39dd3e303cc457a859168512e0bc2bb35ab426e27254dc5917b974d2791e918229b0ff3c294d5825c14363f0421
7
- data.tar.gz: bd62bc67c7182fdbaa0a51703e28ae2af914199e0938c904d7a39e0e5ae0b1ad446b5dc37171d00c4d8fda89c2310c1b8443c9bb9f324f793a786718fa8dd18d
6
+ metadata.gz: 3f1c12bb235c2aa48d7cb04ea936dcb08ccb84c0a730c6ca76b843702cf8e082244b156add8cc30eeb9ef8dfe4281c2a356bb596be313b7243ec7553cae1ca56
7
+ data.tar.gz: 40acfc1aa249e17d6ba544b59e2307742fd48db6f3478ff2e1d2a0e97c982d7c383702a77ebca0dc5980e9ead8ec0d124a8dd793f90162cd82ac10a5cdaae761
data/Changes ADDED
@@ -0,0 +1,12 @@
1
+ v0.1.0 2025-12-31
2
+ --------------------
3
+ Make TinyGID a class not a module
4
+
5
+ v0.0.3 2025-12-25
6
+ --------------------
7
+ Add TinyGID.parse
8
+ Add TinyGID.to_sc
9
+
10
+ v0.0.2 2025-12-11
11
+ --------------------
12
+ 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
@@ -2,9 +2,10 @@
2
2
 
3
3
  require "uri"
4
4
 
5
- module TinyGID
6
- VERSION = "0.0.2"
5
+ class TinyGID
6
+ VERSION = "0.1.0"
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.1.0
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-31 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: []