remote_record 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e59abdc5071a945f3bff2c49d9601fd0a5963fe8476c7df38cae943fe960e67
4
- data.tar.gz: 469a8ba9bdbf28f3b5ab8a9ac8513dda3720bfb122d6adfb09639429454d0ee6
3
+ metadata.gz: b0cee90c4d3ebf7acd0d02efebc3285ed4f568e8d42dae1b591a49d6a243bc9c
4
+ data.tar.gz: b2810727cc559a069b0905f55fb89fe5d3e6d63887cf6a5ef7b4bf8b0b738990
5
5
  SHA512:
6
- metadata.gz: 7865d6b9f270fb7ffeeb2a8d7cfc7ce298cbfc94f7d1414848dc913b913f71762b1214ab95a9cf1c5e46dbefa9da371fbf25fdf9b75a22aceede815d998f54f7
7
- data.tar.gz: 3c472901d7748ec97086a8e9516d8d8edcb10a49cc9a963f5615a146d431f26622c3020cb0367a17f13c5e4df75848c753cde2ac3da0dd06b471bd53dd7e215b
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|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RemoteRecord
4
- VERSION = '0.8.0'
4
+ VERSION = '0.8.1'
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.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Fish