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.
- checksums.yaml +4 -4
- data/Changes +12 -0
- data/README.md +16 -0
- data/lib/tiny_gid.rb +14 -8
- metadata +7 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 130f3c30c294915e45b4e64855cb034edc093deebd77ffdad98211a662660f55
|
|
4
|
+
data.tar.gz: 06d162d16c28dd28909678ce9460a0ec9eaac623f5b3d3271effbfbb6bd3922a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3f1c12bb235c2aa48d7cb04ea936dcb08ccb84c0a730c6ca76b843702cf8e082244b156add8cc30eeb9ef8dfe4281c2a356bb596be313b7243ec7553cae1ca56
|
|
7
|
+
data.tar.gz: 40acfc1aa249e17d6ba544b59e2307742fd48db6f3478ff2e1d2a0e97c982d7c383702a77ebca0dc5980e9ead8ec0d124a8dd793f90162cd82ac10a5cdaae761
|
data/Changes
ADDED
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
|
-
|
|
6
|
-
VERSION = "0.0
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
|
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
|
+
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.
|
|
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: []
|