remote_record 0.7.1 → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 95e6b11dd488bf26b81544c37471498737a26598429ba8290e4e9c8e0f6d79a0
4
- data.tar.gz: cb125226d35be488de6d72651bb1249539d4d2dec487f75e242fc949593b008c
3
+ metadata.gz: 8e59abdc5071a945f3bff2c49d9601fd0a5963fe8476c7df38cae943fe960e67
4
+ data.tar.gz: 469a8ba9bdbf28f3b5ab8a9ac8513dda3720bfb122d6adfb09639429454d0ee6
5
5
  SHA512:
6
- metadata.gz: '08872bedccc7008cbf05129c2e9e791ee73c88bdc222dbaab1ff973bf32b0e24a284690072394c4b6e9a5126f7c0c851e6a2ffbf7ef855909397fbc77d870cbd'
7
- data.tar.gz: d86cd65b6db39f4191d39b0be6e954b56b118daa02534eb0b8c20e10fcf988d9e07ada0fef2fc418e787b1a112dfc300b31df2f7afde199df88bb3fab68d04ca
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RemoteRecord
4
- VERSION = '0.7.1'
4
+ VERSION = '0.8.0'
5
5
  end
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.7.1
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-11 00:00:00.000000000 Z
12
+ date: 2021-02-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord