lhs 19.3.1 → 19.4.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/lib/lhs/concerns/record/merge.rb +26 -0
- data/lib/lhs/record.rb +3 -0
- data/lib/lhs/version.rb +1 -1
- data/spec/record/force_merge_spec.rb +56 -0
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: eec02ca16e6732bb24ad68d18099937f48734dd000326fdfa07cd0365d3a0622
|
|
4
|
+
data.tar.gz: 2e327627fdd24ae4588499376847512ff76d514f90666cbb9115bdcecae0403a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b31fd1517f82df7b7d789888c2f878a9a9ce2f6ac6686b2193210f9a3c5d156f705852bac48974ae495dca7b6da374cec44dd3f0188cdea26891237c459465ea
|
|
7
|
+
data.tar.gz: cf095950ddf9e8e00369f73051b8350dc86e5d3922679d50121983f9414bd343eae85d3e1d44e5a768daa2ba4b2eb24bdbe33737230ecdd5d63ec9cf6b3cf52d
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'active_support'
|
|
4
|
+
|
|
5
|
+
class LHS::Record
|
|
6
|
+
|
|
7
|
+
module Merge
|
|
8
|
+
extend ActiveSupport::Concern
|
|
9
|
+
|
|
10
|
+
def merge(other)
|
|
11
|
+
_record.new(_data.to_h.merge(other.to_h))
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def merge!(other)
|
|
15
|
+
_data._raw.merge!(other.to_h)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def deep_merge(other)
|
|
19
|
+
_record.new(_data.to_h.deep_merge(other.to_h))
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def deep_merge!(other)
|
|
23
|
+
_data._raw.deep_merge!(other.to_h)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
data/lib/lhs/record.rb
CHANGED
|
@@ -27,6 +27,8 @@ class LHS::Record
|
|
|
27
27
|
'lhs/concerns/record/last'
|
|
28
28
|
autoload :Mapping,
|
|
29
29
|
'lhs/concerns/record/mapping'
|
|
30
|
+
autoload :Merge,
|
|
31
|
+
'lhs/concerns/record/merge'
|
|
30
32
|
autoload :Model,
|
|
31
33
|
'lhs/concerns/record/model'
|
|
32
34
|
autoload :Pagination,
|
|
@@ -63,6 +65,7 @@ class LHS::Record
|
|
|
63
65
|
include Last
|
|
64
66
|
include LHS::Inspect
|
|
65
67
|
include Mapping
|
|
68
|
+
include Merge
|
|
66
69
|
include Model
|
|
67
70
|
include Pagination
|
|
68
71
|
include Request
|
data/lib/lhs/version.rb
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails_helper'
|
|
4
|
+
|
|
5
|
+
describe LHS::Record do
|
|
6
|
+
context 'merge' do
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
class Change < LHS::Record
|
|
10
|
+
endpoint 'https://onboarding/places/{id}/change'
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'merges a given hash' do
|
|
15
|
+
stub_request(:get, "https://onboarding/places/1/change")
|
|
16
|
+
.to_return(body: { entry: { name: 'Steve', address: 'Zurich' }, products: ['LBP'] }.to_json)
|
|
17
|
+
record = Change.find(1)
|
|
18
|
+
record.merge!(entry: { name: 'Paul' })
|
|
19
|
+
expect(record.entry.name).to eq 'Paul'
|
|
20
|
+
expect(record.entry.address).to eq nil
|
|
21
|
+
expect(record.products.to_a).to eq ['LBP']
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'merges! a given hash' do
|
|
25
|
+
stub_request(:get, "https://onboarding/places/1/change")
|
|
26
|
+
.to_return(body: { entry: { name: 'Steve', address: 'Zurich' }, products: ['LBP'] }.to_json)
|
|
27
|
+
record = Change.find(1)
|
|
28
|
+
new_record = record.merge(entry: { name: 'Paul' })
|
|
29
|
+
expect(new_record.entry.name).to eq 'Paul'
|
|
30
|
+
expect(new_record.entry.address).to eq nil
|
|
31
|
+
expect(new_record.products.to_a).to eq ['LBP']
|
|
32
|
+
expect(record.entry.name).to eq 'Steve'
|
|
33
|
+
expect(record.entry.address).to eq 'Zurich'
|
|
34
|
+
expect(record.products.to_a).to eq ['LBP']
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'deep_merge! a given hash' do
|
|
38
|
+
stub_request(:get, "https://onboarding/places/1/change")
|
|
39
|
+
.to_return(body: { entry: { name: 'Steve', address: 'Zurich' } }.to_json)
|
|
40
|
+
record = Change.find(1)
|
|
41
|
+
record.deep_merge!(entry: { name: 'Paul' })
|
|
42
|
+
expect(record.entry.name).to eq 'Paul'
|
|
43
|
+
expect(record.entry.address).to eq 'Zurich'
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'deep_merge a given hash' do
|
|
47
|
+
stub_request(:get, "https://onboarding/places/1/change")
|
|
48
|
+
.to_return(body: { entry: { name: 'Steve', address: 'Zurich' } }.to_json)
|
|
49
|
+
record = Change.find(1)
|
|
50
|
+
new_record = record.deep_merge(entry: { name: 'Paul' })
|
|
51
|
+
expect(new_record.entry.name).to eq 'Paul'
|
|
52
|
+
expect(new_record.entry.address).to eq 'Zurich'
|
|
53
|
+
expect(record.entry.name).to eq 'Steve'
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lhs
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 19.
|
|
4
|
+
version: 19.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- https://github.com/local-ch/lhs/graphs/contributors
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-
|
|
11
|
+
date: 2019-06-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activemodel
|
|
@@ -251,6 +251,7 @@ files:
|
|
|
251
251
|
- lib/lhs/concerns/record/first.rb
|
|
252
252
|
- lib/lhs/concerns/record/last.rb
|
|
253
253
|
- lib/lhs/concerns/record/mapping.rb
|
|
254
|
+
- lib/lhs/concerns/record/merge.rb
|
|
254
255
|
- lib/lhs/concerns/record/model.rb
|
|
255
256
|
- lib/lhs/concerns/record/pagination.rb
|
|
256
257
|
- lib/lhs/concerns/record/relations.rb
|
|
@@ -410,6 +411,7 @@ files:
|
|
|
410
411
|
- spec/record/find_in_parallel_spec.rb
|
|
411
412
|
- spec/record/find_spec.rb
|
|
412
413
|
- spec/record/first_spec.rb
|
|
414
|
+
- spec/record/force_merge_spec.rb
|
|
413
415
|
- spec/record/handle_includes_errors_spec.rb
|
|
414
416
|
- spec/record/has_many_spec.rb
|
|
415
417
|
- spec/record/has_one_spec.rb
|
|
@@ -613,6 +615,7 @@ test_files:
|
|
|
613
615
|
- spec/record/find_in_parallel_spec.rb
|
|
614
616
|
- spec/record/find_spec.rb
|
|
615
617
|
- spec/record/first_spec.rb
|
|
618
|
+
- spec/record/force_merge_spec.rb
|
|
616
619
|
- spec/record/handle_includes_errors_spec.rb
|
|
617
620
|
- spec/record/has_many_spec.rb
|
|
618
621
|
- spec/record/has_one_spec.rb
|