globalid 1.0.0 → 1.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/MIT-LICENSE +1 -2
- data/lib/global_id/fixture_set.rb +13 -5
- data/lib/global_id/global_id.rb +14 -12
- data/lib/global_id/locator.rb +0 -1
- data/lib/global_id/railtie.rb +0 -1
- data/lib/global_id/signed_global_id.rb +0 -1
- data/lib/global_id/uri/gid.rb +9 -8
- data/lib/global_id/verifier.rb +0 -1
- data/lib/global_id.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52c4368f15fc8952c9d79189ed9a78e649e0142421721aef338625c19b24c3b9
|
4
|
+
data.tar.gz: 4d6d1c379d45ccaf5761488c540d19cac9d0488b578564964edd88c52073c511
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49ff5a4b4d4f68afdffa67a85b5aebfb3b2f518257ffec22be8a60a29ac5596a67552aae46bebab28a4fe6b37a5802ac520b0f567098617110b2f54c4a74cfcb
|
7
|
+
data.tar.gz: f6ba35dc2c080b0c996bd4529cec1438a35545c693cc0271e25c6b7bdaa8f759de61f26ae6ecf16487d89c7e6e5afc41caab7114541cd8a54ebdf9e2a3ce1f60
|
data/MIT-LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2014-
|
1
|
+
Copyright (c) 2014-2023 David Heinemeier Hansson
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
a copy of this software and associated documentation files (the
|
@@ -18,4 +18,3 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
18
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
19
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
20
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
-
|
@@ -2,12 +2,20 @@
|
|
2
2
|
|
3
3
|
class GlobalID
|
4
4
|
module FixtureSet
|
5
|
-
def
|
6
|
-
|
7
|
-
|
8
|
-
uri = URI::GID.build([GlobalID.app, model_name, identifier, {}])
|
5
|
+
def global_id(fixture_set_name, label, column_type: :integer, **options)
|
6
|
+
create_global_id(fixture_set_name, label, column_type: column_type, klass: GlobalID, **options)
|
7
|
+
end
|
9
8
|
|
10
|
-
|
9
|
+
def signed_global_id(fixture_set_name, label, column_type: :integer, **options)
|
10
|
+
create_global_id(fixture_set_name, label, column_type: column_type, klass: SignedGlobalID, **options)
|
11
11
|
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def create_global_id(fixture_set_name, label, klass:, column_type: :integer, **options)
|
15
|
+
identifier = identify(label, column_type)
|
16
|
+
model_name = default_fixture_model_name(fixture_set_name)
|
17
|
+
uri = URI::GID.build([GlobalID.app, model_name, identifier, {}])
|
18
|
+
klass.new(uri, **options)
|
19
|
+
end
|
12
20
|
end
|
13
21
|
end
|
data/lib/global_id/global_id.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'active_support'
|
2
1
|
require 'active_support/core_ext/string/inflections' # For #model_class constantize
|
3
2
|
require 'active_support/core_ext/array/access'
|
4
3
|
require 'active_support/core_ext/object/try' # For #find
|
@@ -35,18 +34,12 @@ class GlobalID
|
|
35
34
|
|
36
35
|
private
|
37
36
|
def parse_encoded_gid(gid, options)
|
38
|
-
new(Base64.urlsafe_decode64(
|
39
|
-
end
|
40
|
-
|
41
|
-
# We removed the base64 padding character = during #to_param, now we're adding it back so decoding will work
|
42
|
-
def repad_gid(gid)
|
43
|
-
padding_chars = gid.length.modulo(4).zero? ? 0 : (4 - gid.length.modulo(4))
|
44
|
-
gid + ('=' * padding_chars)
|
37
|
+
new(Base64.urlsafe_decode64(gid), options) rescue nil
|
45
38
|
end
|
46
39
|
end
|
47
40
|
|
48
41
|
attr_reader :uri
|
49
|
-
delegate :app, :model_name, :model_id, :params, :to_s, to: :uri
|
42
|
+
delegate :app, :model_name, :model_id, :params, :to_s, :deconstruct_keys, to: :uri
|
50
43
|
|
51
44
|
def initialize(gid, options = {})
|
52
45
|
@uri = gid.is_a?(URI::GID) ? gid : URI::GID.parse(gid)
|
@@ -57,7 +50,13 @@ class GlobalID
|
|
57
50
|
end
|
58
51
|
|
59
52
|
def model_class
|
60
|
-
model_name.constantize
|
53
|
+
model = model_name.constantize
|
54
|
+
|
55
|
+
unless model <= GlobalID
|
56
|
+
model
|
57
|
+
else
|
58
|
+
raise ArgumentError, "GlobalID and SignedGlobalID cannot be used as model_class."
|
59
|
+
end
|
61
60
|
end
|
62
61
|
|
63
62
|
def ==(other)
|
@@ -70,7 +69,10 @@ class GlobalID
|
|
70
69
|
end
|
71
70
|
|
72
71
|
def to_param
|
73
|
-
|
74
|
-
|
72
|
+
Base64.urlsafe_encode64(to_s, padding: false)
|
73
|
+
end
|
74
|
+
|
75
|
+
def as_json(*)
|
76
|
+
to_s
|
75
77
|
end
|
76
78
|
end
|
data/lib/global_id/locator.rb
CHANGED
data/lib/global_id/railtie.rb
CHANGED
data/lib/global_id/uri/gid.rb
CHANGED
@@ -98,6 +98,10 @@ module URI
|
|
98
98
|
"gid://#{app}#{path}#{'?' + query if query}"
|
99
99
|
end
|
100
100
|
|
101
|
+
def deconstruct_keys(_keys)
|
102
|
+
{app: app, model_name: model_name, model_id: model_id, params: params}
|
103
|
+
end
|
104
|
+
|
101
105
|
protected
|
102
106
|
def set_path(path)
|
103
107
|
set_model_components(path) unless defined?(@model_name) && @model_id
|
@@ -123,9 +127,6 @@ module URI
|
|
123
127
|
private
|
124
128
|
COMPONENT = [ :scheme, :app, :model_name, :model_id, :params ].freeze
|
125
129
|
|
126
|
-
# Extracts model_name and model_id from the URI path.
|
127
|
-
PATH_REGEXP = %r(\A/([^/]+)/?([^/]+)?\z)
|
128
|
-
|
129
130
|
def check_host(host)
|
130
131
|
validate_component(host)
|
131
132
|
super
|
@@ -138,18 +139,18 @@ module URI
|
|
138
139
|
|
139
140
|
def check_scheme(scheme)
|
140
141
|
if scheme == 'gid'
|
141
|
-
|
142
|
+
true
|
142
143
|
else
|
143
144
|
raise URI::BadURIError, "Not a gid:// URI scheme: #{inspect}"
|
144
145
|
end
|
145
146
|
end
|
146
147
|
|
147
148
|
def set_model_components(path, validate = false)
|
148
|
-
_, model_name, model_id = path.
|
149
|
-
model_id = CGI.unescape(model_id) if model_id
|
150
|
-
|
149
|
+
_, model_name, model_id = path.split('/', 3)
|
151
150
|
validate_component(model_name) && validate_model_id(model_id, model_name) if validate
|
152
151
|
|
152
|
+
model_id = CGI.unescape(model_id) if model_id
|
153
|
+
|
153
154
|
@model_name = model_name
|
154
155
|
@model_id = model_id
|
155
156
|
end
|
@@ -162,7 +163,7 @@ module URI
|
|
162
163
|
end
|
163
164
|
|
164
165
|
def validate_model_id(model_id, model_name)
|
165
|
-
return model_id unless model_id.blank?
|
166
|
+
return model_id unless model_id.blank? || model_id.include?('/')
|
166
167
|
|
167
168
|
raise MissingModelIdError, "Unable to create a Global ID for " \
|
168
169
|
"#{model_name} without a model id."
|
data/lib/global_id/verifier.rb
CHANGED
data/lib/global_id.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: globalid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -59,7 +59,8 @@ files:
|
|
59
59
|
homepage: http://www.rubyonrails.org
|
60
60
|
licenses:
|
61
61
|
- MIT
|
62
|
-
metadata:
|
62
|
+
metadata:
|
63
|
+
rubygems_mfa_required: 'true'
|
63
64
|
post_install_message:
|
64
65
|
rdoc_options: []
|
65
66
|
require_paths:
|
@@ -75,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
76
|
- !ruby/object:Gem::Version
|
76
77
|
version: '0'
|
77
78
|
requirements: []
|
78
|
-
rubygems_version: 3.
|
79
|
+
rubygems_version: 3.4.1
|
79
80
|
signing_key:
|
80
81
|
specification_version: 4
|
81
82
|
summary: 'Refer to any model with a URI: gid://app/class/id'
|