globalid 0.4.2 → 0.5.2
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: 81180450e9e2f9e9af9593952c70288d868e94b896d62e5f221c5e5f47e507aa
|
4
|
+
data.tar.gz: 18fae57ba4c9a2d8a3815dab68e6383da1f296e23b1dcf4cab106deba1d594aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a61c23c62ea73d195a3674197474c464ed4af1610f5e06bdc90d28ef47d3d71208e19fbb35939e8bb5620aefad1fa6c0dcbf7640534f8aa5a4f749339f41989b
|
7
|
+
data.tar.gz: e119c8418d503a19c0aacb51f214e26dbb75b5a66e8932a4d65eeaf79f852158d03759869c33c30a5b13bcde660b145d41fb39d76cf04d6f138646688a3da9e7
|
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.2
|
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-08-02 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.5.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'
|