ecoportal-api-v2 2.0.10 → 2.0.12
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: 933cb180c2a1d901d3ec065c20527d8d9ee30db24634c20ae3fa2867042311da
|
4
|
+
data.tar.gz: 5c7bf8198ff1ac64b776538c83f80abde8fba0cf6aa6a9f729444548f6b72936
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c47162752062ca85c5a215ce249c3dee0b702d5b11cf095d0f9d9f68bd178af1e9edb4a3bc5c42792133761c6b036cbe2b8a509b4306327a0c72ce0d77a647bc
|
7
|
+
data.tar.gz: 0b2b8d9ac691e3ba75d599adb23012d01600be0d2888bb6a4f1548c3686d8ccac0a95d1aff5e586b241a185b917cd0f2bff05f82b907670148cf18e372d0e81a
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,33 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
+
## [2.0.14] - 2024-11-xx
|
6
|
+
|
7
|
+
### Added
|
8
|
+
|
9
|
+
### Changed
|
10
|
+
|
11
|
+
- upgrade `ecoportal-api` core gem
|
12
|
+
|
13
|
+
### Fixed
|
14
|
+
|
15
|
+
## [2.0.12] - 2024-11-21
|
16
|
+
|
17
|
+
### Changed
|
18
|
+
|
19
|
+
- upgrade `ecoportal-api` core gem
|
20
|
+
|
21
|
+
## [2.0.11] - 2024-10-18
|
22
|
+
|
23
|
+
### Changed
|
24
|
+
|
25
|
+
- upgrade `ecoportal-api` core gem
|
26
|
+
|
27
|
+
### Fixed
|
28
|
+
|
29
|
+
- `Ecoportal::API::V2::Page::Component::ReferenceField#delete`
|
30
|
+
- It wasn't deleting references
|
31
|
+
|
5
32
|
## [2.0.10] - 2024-10-01
|
6
33
|
|
7
34
|
### Added
|
@@ -12,8 +39,6 @@ All notable changes to this project will be documented in this file.
|
|
12
39
|
|
13
40
|
- upgraded core `ecoportal-api` **gem** dependency
|
14
41
|
|
15
|
-
### Fixed
|
16
|
-
|
17
42
|
## [2.0.9] - 2024-08-22
|
18
43
|
|
19
44
|
### Added
|
data/ecoportal-api-v2.gemspec
CHANGED
@@ -25,15 +25,15 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
26
|
spec.require_paths = ['lib']
|
27
27
|
|
28
|
-
spec.add_development_dependency 'pry'
|
28
|
+
spec.add_development_dependency 'pry', '~> 0.14'
|
29
29
|
spec.add_development_dependency 'rake', '>= 13.0.3', '< 14'
|
30
30
|
spec.add_development_dependency 'redcarpet', '>= 3.6.0', '< 4'
|
31
31
|
spec.add_development_dependency 'rspec', '>= 3.12.0', '< 4'
|
32
32
|
spec.add_development_dependency 'rubocop', '~> 1'
|
33
33
|
spec.add_development_dependency 'rubocop-rake', '~> 0'
|
34
|
-
spec.add_development_dependency 'yard',
|
34
|
+
spec.add_development_dependency 'yard', '~> 0.9'
|
35
35
|
|
36
|
-
spec.add_dependency 'ecoportal-api', '~> 0.10', '>= 0.10.
|
36
|
+
spec.add_dependency 'ecoportal-api', '~> 0.10', '>= 0.10.7'
|
37
37
|
spec.add_dependency 'mime-types', '~> 3.5', '>= 3.5.2'
|
38
38
|
end
|
39
39
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# rubocop:disable Naming/MethodParameterName
|
1
2
|
module Ecoportal
|
2
3
|
module API
|
3
4
|
module Common
|
@@ -5,9 +6,9 @@ module Ecoportal
|
|
5
6
|
module HashDiffPatch
|
6
7
|
extend DocHelpers
|
7
8
|
|
8
|
-
ID_KEYS = %w[id]
|
9
|
-
META_KEYS = %w[id patch_ver]
|
10
|
-
NO_CHANGES = "%not-changed!%"
|
9
|
+
ID_KEYS = %w[id].freeze
|
10
|
+
META_KEYS = %w[id patch_ver].freeze
|
11
|
+
NO_CHANGES = "%not-changed!%".freeze
|
11
12
|
|
12
13
|
class << self
|
13
14
|
# The `patch data` is built as follows:
|
@@ -38,14 +39,13 @@ module Ecoportal
|
|
38
39
|
# @param b [Hash] previous hash model
|
39
40
|
# @return [Hash] a `patch data`
|
40
41
|
def patch_diff(a, b)
|
41
|
-
|
42
|
-
when b.is_a?(Hash) && !empty?(b) && empty?(a)
|
42
|
+
if b.is_a?(Hash) && !empty?(b) && empty?(a)
|
43
43
|
patch_delete(b)
|
44
|
-
|
44
|
+
elsif a.is_a?(Hash) && !empty?(a) && empty?(b)
|
45
45
|
patch_new(a)
|
46
|
-
|
46
|
+
elsif a.is_a?(Hash) && b.is_a?(Hash)
|
47
47
|
patch_update(a, b)
|
48
|
-
|
48
|
+
elsif any_array?(a, b)
|
49
49
|
patch_data_array(a, b)
|
50
50
|
else
|
51
51
|
a
|
@@ -54,9 +54,12 @@ module Ecoportal
|
|
54
54
|
|
55
55
|
private
|
56
56
|
|
57
|
-
def equal_values(a, b)
|
57
|
+
def equal_values?(a, b)
|
58
58
|
if a.is_a?(String) || b.is_a?(String)
|
59
|
-
|
59
|
+
a_empty = a.to_s.strip.empty?
|
60
|
+
b_empty = b.to_s.strip.empty?
|
61
|
+
|
62
|
+
return true if a_empty && b_empty
|
60
63
|
end
|
61
64
|
a == b
|
62
65
|
end
|
@@ -66,124 +69,137 @@ module Ecoportal
|
|
66
69
|
def patch_data(a, b = nil, delete: false)
|
67
70
|
{}.tap do |data_hash|
|
68
71
|
if delete
|
69
|
-
patch_ver = (a && a[
|
70
|
-
data_hash[
|
72
|
+
patch_ver = (a && a['patch_ver']) || 1
|
73
|
+
data_hash['patch_ver'] = patch_ver
|
71
74
|
next
|
72
75
|
end
|
76
|
+
|
73
77
|
a.each do |key, a_value|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
+
next if META_KEYS.include?(key)
|
79
|
+
|
80
|
+
b_value = nil
|
81
|
+
|
82
|
+
if b&.key?(key)
|
83
|
+
b_value = b[key]
|
84
|
+
next if equal_values?(a_value, b_value)
|
85
|
+
end
|
86
|
+
|
78
87
|
data_hash[key] = patch_diff(a_value, b_value)
|
88
|
+
|
79
89
|
data_hash.delete(key) if data_hash[key] == NO_CHANGES
|
80
90
|
end
|
91
|
+
|
81
92
|
#if (data_hash.keys - ID_KEYS).empty?
|
82
|
-
if (data_hash.keys - META_KEYS).empty?
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
data_hash["patch_ver"] = b["patch_ver"]
|
89
|
-
elsif a && a.key?("patch_ver")
|
90
|
-
data_hash["patch_ver"] = a["patch_ver"]
|
91
|
-
end
|
92
|
-
data_hash.delete("force_patch")
|
93
|
+
return NO_CHANGES if (data_hash.keys - META_KEYS).empty?
|
94
|
+
|
95
|
+
if b&.key?('patch_ver')
|
96
|
+
data_hash['patch_ver'] = b['patch_ver']
|
97
|
+
elsif a&.key?('patch_ver')
|
98
|
+
data_hash['patch_ver'] = a['patch_ver']
|
93
99
|
end
|
100
|
+
|
101
|
+
data_hash.delete("force_patch")
|
94
102
|
end
|
95
103
|
end
|
96
104
|
|
97
105
|
def patch_delete(b)
|
98
106
|
return NO_CHANGES unless b.is_a?(Hash)
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
nil
|
107
|
-
end
|
107
|
+
return nil unless (id = get_id(b, exception: false))
|
108
|
+
|
109
|
+
{
|
110
|
+
'id' => id,
|
111
|
+
'operation' => 'deleted',
|
112
|
+
'data' => patch_data(b, delete: true)
|
113
|
+
}
|
108
114
|
end
|
109
115
|
|
110
116
|
def patch_new(a)
|
111
117
|
return NO_CHANGES unless a.is_a?(Hash)
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
a
|
120
|
-
end
|
118
|
+
return a unless (id = get_id(a, exception: false))
|
119
|
+
|
120
|
+
{
|
121
|
+
'id' => id,
|
122
|
+
'operation' => 'new',
|
123
|
+
'data' => patch_data(a)
|
124
|
+
}
|
121
125
|
end
|
122
126
|
|
123
127
|
def patch_update(a, b)
|
124
128
|
return NO_CHANGES unless a.is_a?(Hash)
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
else
|
134
|
-
a
|
129
|
+
return a unless (id = get_id(a, exception: false))
|
130
|
+
|
131
|
+
{
|
132
|
+
'id' => id,
|
133
|
+
'operation' => 'changed',
|
134
|
+
'data' => patch_data(a, b)
|
135
|
+
}.tap do |update_hash|
|
136
|
+
return nil unless update_hash['data'] != NO_CHANGES
|
135
137
|
end
|
136
138
|
end
|
137
139
|
|
138
140
|
def patch_data_array(a, b)
|
141
|
+
return patch_data_nested_array(a, b) if nested_array?(a, b)
|
142
|
+
|
143
|
+
patch_data_flat_array(a, b)
|
144
|
+
end
|
145
|
+
|
146
|
+
def patch_data_flat_array(a, b)
|
139
147
|
original_b = b
|
140
|
-
a
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
148
|
+
a ||= []
|
149
|
+
b ||= []
|
150
|
+
|
151
|
+
same_elements =
|
152
|
+
a.length == b.length &&
|
153
|
+
(a & b).length == b.length
|
154
|
+
|
155
|
+
return a unless same_elements
|
156
|
+
return NO_CHANGES if original_b
|
157
|
+
|
158
|
+
a
|
159
|
+
end
|
160
|
+
|
161
|
+
def patch_data_nested_array(a, b)
|
162
|
+
a ||= []
|
163
|
+
b ||= []
|
164
|
+
|
165
|
+
# array with nested elements
|
166
|
+
a_ids = array_ids(a)
|
167
|
+
b_ids = array_ids(b)
|
168
|
+
|
169
|
+
del_ids = b_ids - a_ids
|
170
|
+
oth_ids = b_ids & a_ids
|
171
|
+
new_ids = a_ids - b_ids
|
172
|
+
|
173
|
+
arr_delete = del_ids.map do |id|
|
174
|
+
patch_delete(array_id_item(b, id))
|
175
|
+
end.compact
|
176
|
+
|
177
|
+
arr_update = oth_ids.map do |id|
|
178
|
+
patch_update(array_id_item(a, id), array_id_item(b, id))
|
179
|
+
end.compact
|
180
|
+
|
181
|
+
arr_new = new_ids.map do |id|
|
182
|
+
patch_new(array_id_item(a, id))
|
183
|
+
end.compact
|
184
|
+
|
185
|
+
arr_delete.concat(arr_update).concat(arr_new).tap do |patch_array|
|
186
|
+
# remove data with no `id`
|
187
|
+
patch_array.select! {|item| item.is_a?(Hash)}
|
188
|
+
return NO_CHANGES if patch_array.empty?
|
176
189
|
end
|
177
190
|
end
|
178
191
|
|
179
192
|
def nested_array?(*arr)
|
180
|
-
|
181
|
-
when arr.length > 1
|
193
|
+
if arr.length > 1
|
182
194
|
arr.any? {|a| nested_array?(a)}
|
183
|
-
|
184
|
-
arr = arr.first
|
195
|
+
elsif arr.length == 1
|
196
|
+
arr = arr.first || []
|
185
197
|
arr.any? do |item|
|
186
|
-
item.is_a?(Hash)
|
198
|
+
next false unless item.is_a?(Hash)
|
199
|
+
next true if item.key?('patch_ver')
|
200
|
+
# next true if item.key?('id')
|
201
|
+
|
202
|
+
false
|
187
203
|
end
|
188
204
|
else
|
189
205
|
false
|
@@ -197,11 +213,13 @@ module Ecoportal
|
|
197
213
|
def empty?(a)
|
198
214
|
bool = !a
|
199
215
|
bool ||= a.respond_to?(:empty?) && a.empty?
|
216
|
+
bool
|
200
217
|
end
|
201
|
-
|
202
218
|
end
|
203
219
|
end
|
204
220
|
end
|
205
221
|
end
|
206
222
|
end
|
207
223
|
end
|
224
|
+
|
225
|
+
# rubocop:enable Naming/MethodParameterName
|
@@ -16,18 +16,18 @@ module Ecoportal
|
|
16
16
|
|
17
17
|
def reference_ids
|
18
18
|
references.map do |ref|
|
19
|
-
ref[
|
19
|
+
ref['id']
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
def add(*ref_ids)
|
24
|
-
doc[
|
24
|
+
doc['references'].tap do |refs|
|
25
25
|
ref_ids.each do |ref_id|
|
26
26
|
next if reference_ids.include?(ref_id)
|
27
27
|
refs.push({
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
'id' => ref_id,
|
29
|
+
'weight' => 0,
|
30
|
+
'patch_ver' => 0
|
31
31
|
})
|
32
32
|
end
|
33
33
|
end
|
@@ -39,13 +39,20 @@ module Ecoportal
|
|
39
39
|
|
40
40
|
def delete(*ref_ids)
|
41
41
|
ref_ids.each do |ref_id|
|
42
|
-
doc_ref = doc[
|
43
|
-
df[
|
42
|
+
doc_ref = doc['references'].find do |df|
|
43
|
+
df['id'] == ref_id
|
44
44
|
end
|
45
45
|
|
46
46
|
next unless doc_ref
|
47
47
|
|
48
|
-
|
48
|
+
ori_ref = original_doc['references'].find do |od|
|
49
|
+
od['id'] == ref_id
|
50
|
+
end
|
51
|
+
|
52
|
+
# force patch version
|
53
|
+
ori_ref['patch_ver'] ||= 0
|
54
|
+
|
55
|
+
doc['references'].delete(doc_ref)
|
49
56
|
end
|
50
57
|
end
|
51
58
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ecoportal-api-v2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Segura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -135,7 +135,7 @@ dependencies:
|
|
135
135
|
version: '0.10'
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: 0.10.
|
138
|
+
version: 0.10.7
|
139
139
|
type: :runtime
|
140
140
|
prerelease: false
|
141
141
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -145,7 +145,7 @@ dependencies:
|
|
145
145
|
version: '0.10'
|
146
146
|
- - ">="
|
147
147
|
- !ruby/object:Gem::Version
|
148
|
-
version: 0.10.
|
148
|
+
version: 0.10.7
|
149
149
|
- !ruby/object:Gem::Dependency
|
150
150
|
name: mime-types
|
151
151
|
requirement: !ruby/object:Gem::Requirement
|
@@ -302,7 +302,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
302
302
|
- !ruby/object:Gem::Version
|
303
303
|
version: '0'
|
304
304
|
requirements: []
|
305
|
-
rubygems_version: 3.5.
|
305
|
+
rubygems_version: 3.5.23
|
306
306
|
signing_key:
|
307
307
|
specification_version: 4
|
308
308
|
summary: A collection of helpers for interacting with the ecoPortal MS's V2 API
|