remote_record 0.8.0 → 0.8.1
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/lib/remote_record/reference.rb +15 -1
- 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: b0cee90c4d3ebf7acd0d02efebc3285ed4f568e8d42dae1b591a49d6a243bc9c
|
4
|
+
data.tar.gz: b2810727cc559a069b0905f55fb89fe5d3e6d63887cf6a5ef7b4bf8b0b738990
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86e914f8f66772ae586c17dca8d68e1a0a9b238a11461ff9a302bf8b14f8d9512496a0d0eb516c59746ba2f4dd963314452fe35ff5a16aa6d008016114538e79
|
7
|
+
data.tar.gz: d6c3207d6bf433b98174e1ba87304d6271b8242cdd27960cfe406b71cd16b07e6881371b8c1318d7c5b6be7f9f7917a63dfdc0064ef7db79e9f482eaf41a5056
|
@@ -6,7 +6,7 @@ module RemoteRecord
|
|
6
6
|
# record class (a descendant of RemoteRecord::Base). This is done on
|
7
7
|
# initialize by calling #get on an instance of the remote record class. These
|
8
8
|
# attributes are then accessible on the reference thanks to #method_missing.
|
9
|
-
module Reference
|
9
|
+
module Reference # rubocop:disable Metrics/ModuleLength
|
10
10
|
extend ActiveSupport::Concern
|
11
11
|
|
12
12
|
class_methods do # rubocop:disable Metrics/BlockLength
|
@@ -54,8 +54,22 @@ module RemoteRecord
|
|
54
54
|
new(remote_resource_id: resource['id'], initial_attrs: resource)
|
55
55
|
end
|
56
56
|
|
57
|
+
def remote_find_or_initialize_by(params, &authz_proc)
|
58
|
+
return remote_where(params, &authz_proc).first unless remote_record_class.respond_to?(:find_by)
|
59
|
+
|
60
|
+
resource = remote_record_class.find_by(params, &authz_proc)
|
61
|
+
find_or_initialize_one(id: resource['id'], initial_attrs: resource)
|
62
|
+
end
|
63
|
+
|
57
64
|
private
|
58
65
|
|
66
|
+
def find_or_initialize_one(id:, initial_attrs:)
|
67
|
+
existing_record = no_fetching { find_by(remote_resource_id: id) }
|
68
|
+
return existing_record.tap { |r| r.attrs = initial_attrs } if existing_record.present?
|
69
|
+
|
70
|
+
new(remote_resource_id: id, initial_attrs: initial_attrs)
|
71
|
+
end
|
72
|
+
|
59
73
|
def find_or_initialize_all(remote_resources)
|
60
74
|
no_fetching do
|
61
75
|
pair_remote_resources_with_records(remote_resources) do |unsaved_resources, relation|
|