tiny_gid 0.1.1 → 0.1.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.
- checksums.yaml +4 -4
- data/Changes +9 -0
- data/README.md +4 -0
- data/lib/tiny_gid.rb +19 -2
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4f978825ea29d077b0e40f8fb2c8a2535094f7d95b53a14e71b9cee89b1ac8ce
|
|
4
|
+
data.tar.gz: f71a497d4330b31c776f85a04d0be17f4723a6b6129b61c2eacdf5af2e00ced9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7122a84df61b0dc60f1e99553f6070cac43915ad0c194bca8d74b90c49fe240ba6eee494f9d17003edbb8e5c038ddb86a1e80bd233ee873a54d32aa2ba4d6128
|
|
7
|
+
data.tar.gz: 86643f2b16e82f14861b92eafc26170d4cd4e452cf53fd48f8fc772e8b5623bce4c93bab080fa9d301241835a0307883da819808f8a85b64099e8071a0942633
|
data/Changes
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
v0.1.3 2026-12-05
|
|
2
|
+
--------------------
|
|
3
|
+
Add forced conversion methods, e.g., gid::Foo!(id), that accept a scalar ID or a global ID
|
|
4
|
+
|
|
5
|
+
v0.1.2 2026-04-19
|
|
6
|
+
--------------------
|
|
7
|
+
Add #parse and #to_sc methods to TinyGID (were only class methods prior)
|
|
8
|
+
Fix raise ArgumentError call in initialize()
|
|
9
|
+
|
|
1
10
|
v0.1.1 2026-03-01
|
|
2
11
|
--------------------
|
|
3
12
|
Fix TinyGID.app: don't assume Rails.application.name is defined
|
data/README.md
CHANGED
|
@@ -91,6 +91,10 @@ To put that in 21st century speak: spaces will be replaced with `+` not `%20`.
|
|
|
91
91
|
|
|
92
92
|
No support. Use GlobalID :)
|
|
93
93
|
|
|
94
|
+
## See Also
|
|
95
|
+
|
|
96
|
+
[shopify-gid](https://github.com/estrattonbailey/shopify-gid) - JavaScript encoder/decoder for GIDs returned from the Shopify Storefront API
|
|
97
|
+
|
|
94
98
|
## Author
|
|
95
99
|
|
|
96
100
|
Skye Shaw [skye.shaw -AT- gmail.com]
|
data/lib/tiny_gid.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
require "uri"
|
|
4
4
|
|
|
5
5
|
class TinyGID
|
|
6
|
-
VERSION = "0.1.
|
|
6
|
+
VERSION = "0.1.3"
|
|
7
7
|
FORMAT = "gid://%s/%s/%s"
|
|
8
8
|
REGEX = %r{\Agid://([^/]+)/([^/]+)/([^/?]+)(?:\?(.*?))?\z}
|
|
9
9
|
|
|
@@ -14,6 +14,12 @@ class TinyGID
|
|
|
14
14
|
id = arguments.shift
|
|
15
15
|
raise ArgumentError, "gid::#{name} requires an ID" unless id
|
|
16
16
|
|
|
17
|
+
# gid::Foo!(id) accepts a scalar ID or a global ID. A global ID is returned as-is.
|
|
18
|
+
if name.end_with?("!")
|
|
19
|
+
return id if id.is_a?(String) && id =~ REGEX
|
|
20
|
+
name = name.to_s.chomp("!")
|
|
21
|
+
end
|
|
22
|
+
|
|
17
23
|
params = (arguments[0] || {}).dup
|
|
18
24
|
raise TypeError, "gid::#{name} params must be a Hash. Received: #{params.class}" unless params.is_a?(Hash)
|
|
19
25
|
|
|
@@ -77,10 +83,21 @@ class TinyGID
|
|
|
77
83
|
end
|
|
78
84
|
|
|
79
85
|
def initialize(app)
|
|
80
|
-
raise ArgumentError "app required" if app.to_s.strip.empty?
|
|
86
|
+
raise ArgumentError, "app required" if app.to_s.strip.empty?
|
|
81
87
|
@app = app
|
|
82
88
|
end
|
|
83
89
|
|
|
90
|
+
def parse(gid)
|
|
91
|
+
parsed = TinyGID.parse(gid)
|
|
92
|
+
raise ArgumentError, "gid contains the wrong app: '#{parsed[0]}' must be '#@app'" unless parsed[0] == @app
|
|
93
|
+
|
|
94
|
+
parsed
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def to_sc(gid)
|
|
98
|
+
TinyGID.to_sc(gid)
|
|
99
|
+
end
|
|
100
|
+
|
|
84
101
|
def method_missing(name, *arguments, &block)
|
|
85
102
|
id = arguments.shift
|
|
86
103
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tiny_gid
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Skye Shaw
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-12-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rspec
|