remote_record 0.4.0 → 0.5.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/README.md +20 -2
- data/lib/remote_record.rb +1 -0
- data/lib/remote_record/base.rb +2 -0
- data/lib/remote_record/reference.rb +3 -0
- data/lib/remote_record/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bf471bd03525a3f6dfdfedc1d88e2681264c85e98447607259fec7a94d56ddd
|
4
|
+
data.tar.gz: 076113352a325ee80c09cca58a00cdd8e703a584392319f008393fdae90ddbc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3dc11719e885adf6220ef9b351b1605943ce25220c3e95ee0ee8820175685783777ed7f1bd43f22249f83cb95e8031509e2b85f8be04b65dc33aaab0c4fdca22
|
7
|
+
data.tar.gz: 478180ddc5b281c7a9873313608ad62368f9c947125fd1095b1c61a88e9cce5147637ca1391c801a0af1c2f53e4ac34418256a38563893f926a4f55ee37d62b4
|
data/README.md
CHANGED
@@ -1,6 +1,20 @@
|
|
1
|
-
|
1
|
+

|
2
2
|
|
3
|
-
|
3
|
+
---
|
4
|
+
|
5
|
+

|
6
|
+
[](https://badge.fury.io/rb/remote_record)
|
7
|
+
|
8
|
+
Every API speaks a different language. Maybe it's REST, maybe it's SOAP, maybe
|
9
|
+
it's GraphQL. Maybe it's got its own Ruby client, or maybe you need to roll your
|
10
|
+
own. But what if you could just pretend it existed in your database?
|
11
|
+
|
12
|
+
RemoteRecord provides a consistent ActiveRecord inspired interface for all of
|
13
|
+
your application's APIs. Store remote resources by ID, and RemoteRecord will
|
14
|
+
auto-populate instances of your ActiveRecord model with their attributes from
|
15
|
+
the API. Whether you're dealing with a user on GitHub, a track on Spotify, a
|
16
|
+
place on Google Maps, or a resource on your internal infrastructure, you can use
|
17
|
+
RemoteRecord to wrap fetching it.
|
4
18
|
|
5
19
|
## Setup
|
6
20
|
|
@@ -114,3 +128,7 @@ gain support for caching.
|
|
114
128
|
|
115
129
|
You might want to force a fresh request in some instances, even if you're using
|
116
130
|
`memoize`. To do this, call `fresh` on a reference, and it'll be repopulated.
|
131
|
+
|
132
|
+
### Skip fetching
|
133
|
+
|
134
|
+
You might not want to make a request on initialize sometimes. In this case, pass `fetching: false` to your query or `new` to make sure the resource isn't fetched.
|
data/lib/remote_record.rb
CHANGED
data/lib/remote_record/base.rb
CHANGED
@@ -27,6 +27,7 @@ module RemoteRecord
|
|
27
27
|
|
28
28
|
# rubocop:disable Metrics/BlockLength
|
29
29
|
included do
|
30
|
+
include ActiveSupport::Rescuable
|
30
31
|
attr_accessor :fetching
|
31
32
|
|
32
33
|
after_initialize do |reference|
|
@@ -52,6 +53,8 @@ module RemoteRecord
|
|
52
53
|
|
53
54
|
def fetch_remote_resource
|
54
55
|
instance.fetch if fetching
|
56
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
57
|
+
rescue_with_handler(e) || raise
|
55
58
|
end
|
56
59
|
|
57
60
|
def fresh
|