globalid 0.4.2 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of globalid might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +28 -0
- data/lib/global_id/identification.rb +0 -4
- data/lib/global_id/railtie.rb +3 -2
- data/lib/global_id/uri/gid.rb +5 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91ad4d8c34957591df10703702ee81e259afaebe296bf0163788952bc3acdcd6
|
4
|
+
data.tar.gz: 1bd763051bf53016df8faf674dfab0f38aae178db11d0b66ca416cdd9ba0910d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00ece65591def5d2420aa732d8a7482c14922f45bd10c6b3be55f4340587d90985e967e9f68951fb840440c1584785a6c9a5f6ff0db8c38e2539cbd6ea842c94
|
7
|
+
data.tar.gz: c34a0627c13e63e3535be150787eca885d0bbb717e66f5b0700cb5a9ccb30446af260defa7b3a79ad0371f4f1235d77079520c6e67148d10edc6f2bf458a700a
|
data/README.md
CHANGED
@@ -133,6 +133,34 @@ GlobalID::Locator.locate_signed(signup_person_sgid.to_s, for: 'signup_form')
|
|
133
133
|
# => #<Person:0x007fae94bf6298 @id="1">
|
134
134
|
```
|
135
135
|
|
136
|
+
### Locating many Global IDs
|
137
|
+
|
138
|
+
When needing to locate many Global IDs use `GlobalID::Locator.locate_many` or `GlobalID::Locator.locate_many_signed` for Signed Global IDs to allow loading
|
139
|
+
Global IDs more efficiently.
|
140
|
+
|
141
|
+
For instance, the default locator passes every `model_id` per `model_name` thus
|
142
|
+
using `model_name.where(id: model_ids)` versus `GlobalID::Locator.locate`'s `model_name.find(id)`.
|
143
|
+
|
144
|
+
In the case of looking up Global IDs from a database, it's only necessary to query
|
145
|
+
once per `model_name` as shown here:
|
146
|
+
|
147
|
+
```ruby
|
148
|
+
gids = users.concat(people).sort_by(&:id).map(&:to_global_id)
|
149
|
+
# => [#<GlobalID:0x00007ffd6a8411a0 @uri=#<URI::GID gid://app/User/1>>,
|
150
|
+
#<GlobalID:0x00007ffd675d32b8 @uri=#<URI::GID gid://app/Student/1>>,
|
151
|
+
#<GlobalID:0x00007ffd6a840b10 @uri=#<URI::GID gid://app/User/2>>,
|
152
|
+
#<GlobalID:0x00007ffd675d2c28 @uri=#<URI::GID gid://app/Student/2>>,
|
153
|
+
#<GlobalID:0x00007ffd6a840480 @uri=#<URI::GID gid://app/User/3>>,
|
154
|
+
#<GlobalID:0x00007ffd675d2598 @uri=#<URI::GID gid://app/Student/3>>]
|
155
|
+
|
156
|
+
GlobalID::Locator.locate_many gids
|
157
|
+
# SELECT "users".* FROM "users" WHERE "users"."id" IN ($1, $2, $3) [["id", 1], ["id", 2], ["id", 3]]
|
158
|
+
# SELECT "students".* FROM "students" WHERE "students"."id" IN ($1, $2, $3) [["id", 1], ["id", 2], ["id", 3]]
|
159
|
+
# => [#<User id: 1>, #<Student id: 1>, #<User id: 2>, #<Student id: 2>, #<User id: 3>, #<Student id: 3>]
|
160
|
+
```
|
161
|
+
|
162
|
+
Note the order is maintained in the returned results.
|
163
|
+
|
136
164
|
### Custom App Locator
|
137
165
|
|
138
166
|
A custom locator can be set for an app by calling `GlobalID::Locator.use` and providing an app locator to use for that app.
|
data/lib/global_id/railtie.rb
CHANGED
@@ -5,6 +5,7 @@ else
|
|
5
5
|
require 'global_id'
|
6
6
|
require 'active_support'
|
7
7
|
require 'active_support/core_ext/string/inflections'
|
8
|
+
require 'active_support/core_ext/integer/time'
|
8
9
|
|
9
10
|
class GlobalID
|
10
11
|
# = GlobalID Railtie
|
@@ -18,11 +19,11 @@ class GlobalID
|
|
18
19
|
default_app_name = app.railtie_name.remove('_application').dasherize
|
19
20
|
|
20
21
|
GlobalID.app = app.config.global_id.app ||= default_app_name
|
21
|
-
SignedGlobalID.expires_in = app.config.global_id.expires_in
|
22
|
+
SignedGlobalID.expires_in = app.config.global_id.fetch(:expires_in, default_expires_in)
|
22
23
|
|
23
24
|
config.after_initialize do
|
24
25
|
GlobalID.app = app.config.global_id.app ||= default_app_name
|
25
|
-
SignedGlobalID.expires_in = app.config.global_id.expires_in
|
26
|
+
SignedGlobalID.expires_in = app.config.global_id.fetch(:expires_in, default_expires_in)
|
26
27
|
|
27
28
|
app.config.global_id.verifier ||= begin
|
28
29
|
GlobalID::Verifier.new(app.key_generator.generate_key('signed_global_ids'))
|
data/lib/global_id/uri/gid.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: 0.
|
4
|
+
version: 0.5.1
|
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: 2021-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '5.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '5.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,14 +67,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
67
67
|
requirements:
|
68
68
|
- - ">="
|
69
69
|
- !ruby/object:Gem::Version
|
70
|
-
version:
|
70
|
+
version: 2.6.0
|
71
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
requirements: []
|
77
|
-
rubygems_version: 3.
|
77
|
+
rubygems_version: 3.2.24
|
78
78
|
signing_key:
|
79
79
|
specification_version: 4
|
80
80
|
summary: 'Refer to any model with a URI: gid://app/class/id'
|