remote_record 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -0
- data/lib/remote_record/reference.rb +7 -0
- data/lib/remote_record/version.rb +1 -1
- 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: 8e59abdc5071a945f3bff2c49d9601fd0a5963fe8476c7df38cae943fe960e67
|
4
|
+
data.tar.gz: 469a8ba9bdbf28f3b5ab8a9ac8513dda3720bfb122d6adfb09639429454d0ee6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7865d6b9f270fb7ffeeb2a8d7cfc7ce298cbfc94f7d1414848dc913b913f71762b1214ab95a9cf1c5e46dbefa9da371fbf25fdf9b75a22aceede815d998f54f7
|
7
|
+
data.tar.gz: 3c472901d7748ec97086a8e9516d8d8edcb10a49cc9a963f5615a146d431f26622c3020cb0367a17f13c5e4df75848c753cde2ac3da0dd06b471bd53dd7e215b
|
data/README.md
CHANGED
@@ -247,3 +247,23 @@ sort of like a `Faraday` cage, pun entirely intended.
|
|
247
247
|
If you're using `remote_all` or `remote_where` to fetch using your API, that'll
|
248
248
|
automatically use this behind the scenes, then set `attrs` to the response
|
249
249
|
value.
|
250
|
+
|
251
|
+
### Finding a record without having its canonical ID
|
252
|
+
|
253
|
+
On many platforms, you might find yourself searching for users by email or
|
254
|
+
username. Those aren't canonical IDs - they could change. But searching for them
|
255
|
+
by either of those things is a safe bet as a user, nine times out of ten.
|
256
|
+
|
257
|
+
Similarly, you (or your users) might not always have a remote resource's ID
|
258
|
+
upfront. You might, however, have something unique enough to discern it from
|
259
|
+
other records, like a user-facing ID. A good example is a pull request reference
|
260
|
+
on GitHub - using the repo name, owner's username, and pull request ID, you can
|
261
|
+
find a pull request.
|
262
|
+
|
263
|
+
Of course, that shouldn't be your canonical source, because two of those things
|
264
|
+
could change. You could change your username, and you could rename the repo. But
|
265
|
+
it's useful to be able to search by those things, right?
|
266
|
+
|
267
|
+
Implement `find_by` on your remote_record class, and RemoteRecord will use it.
|
268
|
+
If you don't, RemoteRecord will fall back to `remote_where`. This takes the same
|
269
|
+
params as other class-level RemoteRecord methods, including an auth proc.
|
@@ -47,6 +47,13 @@ module RemoteRecord
|
|
47
47
|
find_or_initialize_all(remote_record_class.where(params, &authz_proc))
|
48
48
|
end
|
49
49
|
|
50
|
+
def remote_find_by(params, &authz_proc)
|
51
|
+
return remote_where(params, &authz_proc).first unless remote_record_class.respond_to?(:find_by)
|
52
|
+
|
53
|
+
resource = remote_record_class.find_by(params, &authz_proc)
|
54
|
+
new(remote_resource_id: resource['id'], initial_attrs: resource)
|
55
|
+
end
|
56
|
+
|
50
57
|
private
|
51
58
|
|
52
59
|
def find_or_initialize_all(remote_resources)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remote_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Fish
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-02-
|
12
|
+
date: 2021-02-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|