materialist 3.7.0 → 3.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cef103c710bdfcf4b9a5ee36bad6b4474bc88c194a436bb935aa15b090a69f0
|
4
|
+
data.tar.gz: f91fcd7467e60889d34ed33ed57c08ac67a6365a4168d5c52e7dd8564f2ec331
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc547ca1823460c517b5b1a8720e3259004bcbf1f8b92c91847d90d9ea6638af4ffb39d2f7a50994fc8070b997b1fb61b69a12ae49e2009125c61af4e2a5ac26
|
7
|
+
data.tar.gz: dd6b84e5541132b052bce821853348a62a0fd6608837f7d141b2bb472a6c32eb0fb01211ad07837c093ed62da9b55788a720034f1d398aef9e9eda7ba0b09d1a
|
data/README.md
CHANGED
@@ -155,8 +155,8 @@ class ZoneMaterializer
|
|
155
155
|
|
156
156
|
persist_to :zone
|
157
157
|
|
158
|
-
source_key :source_id do |url|
|
159
|
-
/(\d+)\/?$/.match(url)[1]
|
158
|
+
source_key :source_id do |url, response|
|
159
|
+
/(\d+)\/?$/.match(url)[1] # or response.dig(:some_attr)
|
160
160
|
end
|
161
161
|
|
162
162
|
capture :id, as: :orderweb_id
|
@@ -189,10 +189,10 @@ describes the name of the active record model to be used.
|
|
189
189
|
If missing, materialist skips materialising the resource itself, but will continue
|
190
190
|
with any other functionality -- such as `materialize_link`.
|
191
191
|
|
192
|
-
#### `source_key <column> <
|
192
|
+
#### `source_key <column> <parser_block> (default: url, resource response body[create, update action only])`
|
193
193
|
describes the column used to persist the unique identifier parsed from the url_parser_block.
|
194
194
|
By default the column used is `:source_url` and the original `url` is used as the identifier.
|
195
|
-
Passing an optional block allows you to extract an identifier from the URL.
|
195
|
+
Passing an optional block allows you to extract an identifier from the URL and captured attributes.
|
196
196
|
|
197
197
|
#### `capture <key>, as: <column> (default: key)`
|
198
198
|
describes mapping a resource key to a database column.
|
@@ -38,9 +38,9 @@ module Materialist
|
|
38
38
|
__materialist_options[:sidekiq_options] = options
|
39
39
|
end
|
40
40
|
|
41
|
-
def source_key(key, &
|
41
|
+
def source_key(key, &source_key_parser)
|
42
42
|
__materialist_options[:source_key] = key
|
43
|
-
__materialist_options[:
|
43
|
+
__materialist_options[:source_key_parser] = source_key_parser
|
44
44
|
end
|
45
45
|
|
46
46
|
# This method is meant to be used for cases when the application needs
|
@@ -59,7 +59,7 @@ module Materialist
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def upsert_record
|
62
|
-
model_class.find_or_initialize_by(source_lookup(url)).tap do |entity|
|
62
|
+
model_class.find_or_initialize_by(source_lookup(url, resource)).tap do |entity|
|
63
63
|
send_messages(before_upsert, entity) unless before_upsert.nil?
|
64
64
|
before_upsert_with_payload&.each { |m| instance.send(m, entity, resource) }
|
65
65
|
entity.update_attributes!(attributes)
|
@@ -110,12 +110,12 @@ module Materialist
|
|
110
110
|
options.fetch(:source_key, :source_url)
|
111
111
|
end
|
112
112
|
|
113
|
-
def
|
114
|
-
options[:
|
113
|
+
def source_key_parser
|
114
|
+
options[:source_key_parser] || ->(url, data) { url }
|
115
115
|
end
|
116
116
|
|
117
|
-
def source_lookup(url)
|
118
|
-
@_source_lookup ||= { source_key =>
|
117
|
+
def source_lookup(url, resource={})
|
118
|
+
@_source_lookup ||= { source_key => source_key_parser.call(url, resource) }
|
119
119
|
end
|
120
120
|
|
121
121
|
def attributes
|
data/lib/materialist/version.rb
CHANGED
@@ -50,7 +50,7 @@ RSpec.describe Materialist::Materializer::Internals::Materializer do
|
|
50
50
|
let(:source_body) {{ _links: { city: { href: city_url }}, name: 'jack', age: 30 }}
|
51
51
|
let(:defined_source_id) { 65 }
|
52
52
|
let(:defined_source_url) { "https://service.dev/defined_sources/#{defined_source_id}" }
|
53
|
-
let(:defined_source_body) {{ name: 'ben' }}
|
53
|
+
let(:defined_source_body) {{ name: 'ben', id: defined_source_id }}
|
54
54
|
|
55
55
|
def stub_resource(url, body)
|
56
56
|
stub_request(:get, url).to_return(
|
@@ -380,62 +380,87 @@ RSpec.describe Materialist::Materializer::Internals::Materializer do
|
|
380
380
|
end
|
381
381
|
|
382
382
|
context "entity based on the source_key column" do
|
383
|
-
|
384
|
-
|
385
|
-
|
383
|
+
shared_examples 'an upsert materialization event' do
|
384
|
+
context "when creating" do
|
385
|
+
let(:perform) { subject.perform(defined_source_url, action) }
|
386
386
|
|
387
|
-
|
388
|
-
|
389
|
-
source_key :source_id do |url|
|
390
|
-
url.split('/').last.to_i
|
387
|
+
it "creates based on source_key" do
|
388
|
+
expect{perform}.to change{DefinedSource.count}.by 1
|
391
389
|
end
|
392
390
|
|
393
|
-
|
391
|
+
it "sets the correct source key" do
|
392
|
+
perform
|
393
|
+
inserted = DefinedSource.find_by(source_id: defined_source_id)
|
394
|
+
expect(inserted.source_id).to eq defined_source_id
|
395
|
+
expect(inserted.name).to eq defined_source_body[:name]
|
396
|
+
end
|
394
397
|
end
|
395
|
-
end
|
396
398
|
|
397
|
-
|
398
|
-
|
399
|
+
context "when updating" do
|
400
|
+
let(:action) { :update }
|
401
|
+
let!(:record) { DefinedSource.create!(source_id: defined_source_id, name: 'mo') }
|
402
|
+
let(:perform) { subject.perform(defined_source_url, action) }
|
399
403
|
|
400
|
-
|
401
|
-
|
402
|
-
|
404
|
+
it "updates based on source_key" do
|
405
|
+
perform
|
406
|
+
expect(DefinedSource.count).to eq 1
|
407
|
+
end
|
403
408
|
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
+
it "updates the existing record" do
|
410
|
+
perform
|
411
|
+
inserted = DefinedSource.find_by(source_id: defined_source_id)
|
412
|
+
expect(inserted.source_id).to eq defined_source_id
|
413
|
+
expect(inserted.name).to eq defined_source_body[:name]
|
414
|
+
end
|
409
415
|
end
|
410
416
|
end
|
411
417
|
|
412
|
-
context
|
413
|
-
|
414
|
-
|
415
|
-
|
418
|
+
context 'with url source key parser' do
|
419
|
+
subject do
|
420
|
+
Class.new do
|
421
|
+
include Materialist::Materializer
|
422
|
+
|
423
|
+
persist_to :defined_source
|
424
|
+
|
425
|
+
source_key :source_id do |url|
|
426
|
+
url.split('/').last.to_i
|
427
|
+
end
|
416
428
|
|
417
|
-
|
418
|
-
|
419
|
-
expect(DefinedSource.count).to eq 1
|
429
|
+
capture :name
|
430
|
+
end
|
420
431
|
end
|
421
432
|
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
433
|
+
context "when deleting" do
|
434
|
+
let(:action) { :delete }
|
435
|
+
let!(:record) { DefinedSource.create!(source_id: defined_source_id, name: 'mo') }
|
436
|
+
let(:perform) { subject.perform(defined_source_url, action) }
|
437
|
+
|
438
|
+
it "deletes based on source_key" do
|
439
|
+
perform
|
440
|
+
expect(DefinedSource.count).to eq 0
|
441
|
+
end
|
427
442
|
end
|
443
|
+
|
444
|
+
it_behaves_like 'an upsert materialization event'
|
428
445
|
end
|
429
446
|
|
430
|
-
context
|
431
|
-
|
432
|
-
|
433
|
-
|
447
|
+
context 'with resource source key parser' do
|
448
|
+
subject do
|
449
|
+
Class.new do
|
450
|
+
include Materialist::Materializer
|
434
451
|
|
435
|
-
|
436
|
-
|
437
|
-
|
452
|
+
persist_to :defined_source
|
453
|
+
|
454
|
+
source_key :source_id do |_, resource|
|
455
|
+
resource.dig(:id)
|
456
|
+
end
|
457
|
+
|
458
|
+
capture :name
|
459
|
+
capture :id
|
460
|
+
end
|
438
461
|
end
|
462
|
+
|
463
|
+
it_behaves_like 'an upsert materialization event'
|
439
464
|
end
|
440
465
|
end
|
441
466
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: materialist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mo Valipour
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
@@ -178,7 +178,7 @@ dependencies:
|
|
178
178
|
- - ">="
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: '0'
|
181
|
-
description:
|
181
|
+
description:
|
182
182
|
email:
|
183
183
|
- valipour@gmail.com
|
184
184
|
executables: []
|
@@ -232,7 +232,7 @@ homepage: http://github.com/deliveroo/materialist
|
|
232
232
|
licenses:
|
233
233
|
- MIT
|
234
234
|
metadata: {}
|
235
|
-
post_install_message:
|
235
|
+
post_install_message:
|
236
236
|
rdoc_options: []
|
237
237
|
require_paths:
|
238
238
|
- lib
|
@@ -247,8 +247,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
247
247
|
- !ruby/object:Gem::Version
|
248
248
|
version: '0'
|
249
249
|
requirements: []
|
250
|
-
rubygems_version: 3.0.
|
251
|
-
signing_key:
|
250
|
+
rubygems_version: 3.0.9
|
251
|
+
signing_key:
|
252
252
|
specification_version: 4
|
253
253
|
summary: Utilities to materialize routemaster topics
|
254
254
|
test_files:
|