ecoportal-api-v2 2.0.9 → 2.0.11

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: 5640c86f2f87990f7d4c3906f4732ee196b757966c3c3cc08f0a87e458ccb4a5
4
- data.tar.gz: c90366a05f7c35fc77a0d8374384258277092e9d7b3ee25f458ab815a41162ce
3
+ metadata.gz: 0a93753cf1640abe95935d227eb0518f39e4dc007da9c2771d872bbcc7f0f7ff
4
+ data.tar.gz: 7fc6475b6d05011ab94bc3774922afe0e6c0501420633556c7580455dc26724e
5
5
  SHA512:
6
- metadata.gz: 2aa98c2d721ff735425e9c21aee036698e5467a3c010e35d84921d9352ae12400f627c8a2a16359177ac22e583a417b05302c852b513b3d6d6bc4743b8cac170
7
- data.tar.gz: f356407dfd38797be43f29ad02d7a1772c7136cf1d686eb2554dc226316184aa70e27c89b9de39d52725ab6b95505149a1d7b38a39897915862d8a0dfa33e3ca
6
+ metadata.gz: 210a1b99d67ee7aa17e5ae3050a1c23d65a4a41c625dfa6d5cd016e8a32f1d346aff9c2ce94a846188a47a74f97ffde28df05af7425d9269aebdc5a84bb8b0c8
7
+ data.tar.gz: 841d3d7e2b8396f673e76d7b6e14eeea773acda0bc323f60af86741032ff2e6a6bc4c79a6bce873f8b7a51f699718b67d0103773b690cd9236421b7ff75cff27
data/CHANGELOG.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
- ## [2.0.10] - 2024-08-xx
5
+ ## [2.0.12] - 2024-10-xx
6
6
 
7
7
  ### Added
8
8
 
@@ -10,6 +10,27 @@ All notable changes to this project will be documented in this file.
10
10
 
11
11
  ### Fixed
12
12
 
13
+ ## [2.0.11] - 2024-10-18
14
+
15
+ ### Changed
16
+
17
+ - upgrade `ecoportal-api` core gem
18
+
19
+ ### Fixed
20
+
21
+ - `Ecoportal::API::V2::Page::Component::ReferenceField#delete`
22
+ - It wasn't deleting references
23
+
24
+ ## [2.0.10] - 2024-10-01
25
+
26
+ ### Added
27
+
28
+ - development dependency: `rubocop`
29
+
30
+ ### Changed
31
+
32
+ - upgraded core `ecoportal-api` **gem** dependency
33
+
13
34
  ## [2.0.9] - 2024-08-22
14
35
 
15
36
  ### Added
data/README.md CHANGED
@@ -1,5 +1,3 @@
1
- **Originally ---> 'ecoportal-api-oozes'**
2
-
3
1
  # Ecoportal::API::V2
4
2
 
5
3
  This is a basic collection of helpers that can be used to interact with the
@@ -15,12 +13,11 @@ gem 'ecoportal-api-v2', require: %w[ecoportal/api-v2]
15
13
 
16
14
  And then execute:
17
15
 
18
- $ bundle
16
+ bundle
19
17
 
20
18
  Or install it yourself as:
21
19
 
22
- $ gem install ecoportal-api-v2
23
-
20
+ gem install ecoportal-api-v2
24
21
 
25
22
  ## Changelog
26
23
 
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
+ require 'rubocop/rake_task'
3
4
  require "yard"
4
5
  require "redcarpet"
5
6
 
@@ -16,12 +17,20 @@ RSpec::Core::RakeTask.new(:spec_fast) do |task|
16
17
  task.rspec_opts = ['--fail-fast', '--backtrace']
17
18
  end
18
19
 
20
+ desc "run rubocop diaplying cop names"
21
+ RuboCop::RakeTask.new(:rubocop) do |t|
22
+ t.options = ['--display-cop-names']
23
+ end
24
+
19
25
  # default task name is yard
20
26
  desc "Yard: generate all the documentation"
21
27
  YARD::Rake::YardocTask.new(:doc) do |t|
22
28
  #t.files = ['lib/**/*.rb']
23
29
  end
24
30
 
25
- task :default => [:spec]
26
- task :rspec_trace => :spec_trace
27
- task :rspec_fast => :spec_fast
31
+ desc "default task: runs rubocop and rspec"
32
+ task :default do
33
+ Rake::Task[:rubocop].invoke
34
+ ensure
35
+ Rake::Task[:spec].invoke
36
+ end
@@ -1,12 +1,14 @@
1
+ # rubocop:disable Gemspec/DevelopmentDependencies
1
2
  lib = File.expand_path('lib', __dir__)
2
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "ecoportal/api/v2_version"
4
+
5
+ require 'ecoportal/api/v2_version'
4
6
 
5
7
  Gem::Specification.new do |spec|
6
- spec.name = "ecoportal-api-v2"
8
+ spec.name = 'ecoportal-api-v2'
7
9
  spec.version = Ecoportal::API::GEM2_VERSION
8
- spec.authors = ["Oscar Segura"]
9
- spec.email = ["rien@ecoportal.co.nz", "oscar@ecoportal.co.nz", "bozydar@ecoportal.co.nz"]
10
+ spec.authors = ['Oscar Segura']
11
+ spec.email = ['oscar@ecoportal.co.nz']
10
12
 
11
13
  spec.summary = "A collection of helpers for interacting with the ecoPortal MS's V2 API"
12
14
  spec.homepage = "https://www.ecoportal.com"
@@ -19,16 +21,20 @@ Gem::Specification.new do |spec|
19
21
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
22
  f.match(%r{^(test|spec|features)/})
21
23
  end
22
- spec.bindir = "exe"
24
+ spec.bindir = 'exe'
23
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
- spec.require_paths = ["lib"]
26
+ spec.require_paths = ['lib']
25
27
 
26
- spec.add_development_dependency "pry" , '~> 0.14'
27
- spec.add_development_dependency "rake", '>= 13.0.3', "< 14"
28
- spec.add_development_dependency "redcarpet", '>= 3.6.0', "< 4"
29
- spec.add_development_dependency "rspec", '>= 3.12.0', "< 4"
30
- spec.add_development_dependency "yard", '~> 0.9.34'
28
+ spec.add_development_dependency 'pry', '~> 0.14'
29
+ spec.add_development_dependency 'rake', '>= 13.0.3', '< 14'
30
+ spec.add_development_dependency 'redcarpet', '>= 3.6.0', '< 4'
31
+ spec.add_development_dependency 'rspec', '>= 3.12.0', '< 4'
32
+ spec.add_development_dependency 'rubocop', '~> 1'
33
+ spec.add_development_dependency 'rubocop-rake', '~> 0'
34
+ spec.add_development_dependency 'yard', '~> 0.9'
31
35
 
32
- spec.add_dependency 'ecoportal-api', '~> 0.10'
33
- spec.add_dependency 'mime-types', '~> 3.5', '>= 3.5.2'
36
+ spec.add_dependency 'ecoportal-api', '~> 0.10', '>= 0.10.5'
37
+ spec.add_dependency 'mime-types', '~> 3.5', '>= 3.5.2'
34
38
  end
39
+
40
+ # rubocop:enable Gemspec/DevelopmentDependencies
@@ -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
- case
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
- when a.is_a?(Hash) && !empty?(a) && empty?(b)
44
+ elsif a.is_a?(Hash) && !empty?(a) && empty?(b)
45
45
  patch_new(a)
46
- when a.is_a?(Hash) && b.is_a?(Hash)
46
+ elsif a.is_a?(Hash) && b.is_a?(Hash)
47
47
  patch_update(a, b)
48
- when any_array?(a, b)
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
- return true if a.to_s.strip.empty? && b.to_s.strip.empty?
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["patch_ver"]) || 1
70
- data_hash["patch_ver"] = patch_ver
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
- b_value = b[key] if b_has_key = b && b.key?(key)
75
- is_meta_key = META_KEYS.include?(key)
76
- skip_equals = b_has_key && equal_values(a_value, b_value)
77
- next if is_meta_key || skip_equals
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
- return NO_CHANGES
84
- else
85
- #patch_ver = (b && b["patch_ver"]) || 1
86
- #data_hash["patch_ver"] = patch_ver
87
- if b && b.key?("patch_ver")
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
- if id = get_id(b, exception: false)
100
- {
101
- "id" => id,
102
- "operation" => "deleted",
103
- "data" => patch_data(b, delete: true)
104
- }
105
- else
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
- if id = get_id(a, exception: false)
113
- {
114
- "id" => id,
115
- "operation" => "new",
116
- "data" => patch_data(a)
117
- }
118
- else
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
- if id = get_id(a, exception: false)
126
- {
127
- "id" => id,
128
- "operation" => "changed",
129
- "data" => patch_data(a, b)
130
- }.tap do |update_hash|
131
- return nil unless update_hash["data"] != NO_CHANGES
132
- end
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 ||= []; b ||= []
141
- if !nested_array?(a, b)
142
- if a.length == b.length && (a & b).length == b.length
143
- if original_b
144
- NO_CHANGES
145
- else
146
- a
147
- end
148
- else
149
- a
150
- end
151
- else # array with nested elements
152
- a_ids = array_ids(a)
153
- b_ids = array_ids(b)
154
-
155
- del_ids = b_ids - a_ids
156
- oth_ids = b_ids & a_ids
157
- new_ids = a_ids - b_ids
158
-
159
- arr_delete = del_ids.map do |id|
160
- patch_delete(array_id_item(b, id))
161
- end.compact
162
-
163
- arr_update = oth_ids.map do |id|
164
- patch_update(array_id_item(a, id), array_id_item(b, id))
165
- end.compact
166
-
167
- arr_new = new_ids.map do |id|
168
- patch_new(array_id_item(a, id))
169
- end.compact
170
-
171
- (arr_delete.concat(arr_update).concat(arr_new)).tap do |patch_array|
172
- # remove data with no `id`
173
- patch_array.reject! {|item| !item.is_a?(Hash)}
174
- return NO_CHANGES if patch_array.empty?
175
- end
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
- case
181
- when arr.length > 1
193
+ if arr.length > 1
182
194
  arr.any? {|a| nested_array?(a)}
183
- when arr.length == 1
184
- arr = arr.first
195
+ elsif arr.length == 1
196
+ arr = arr.first || []
185
197
  arr.any? do |item|
186
- item.is_a?(Hash) && item.has_key?("patch_ver")
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["id"]
19
+ ref['id']
20
20
  end
21
21
  end
22
22
 
23
23
  def add(*ref_ids)
24
- doc["references"].tap do |refs|
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
- "id" => ref_id,
29
- "weight" => 0,
30
- "patch_ver" => 0
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["references"].find do |df|
43
- df["id"] == ref_id
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
- doc["references"].delete(doc_ref)
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
 
@@ -1,5 +1,5 @@
1
1
  module Ecoportal
2
2
  module API
3
- GEM2_VERSION = '2.0.9'.freeze
3
+ GEM2_VERSION = '2.0.11'.freeze
4
4
  end
5
5
  end
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.9
4
+ version: 2.0.11
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-08-22 00:00:00.000000000 Z
11
+ date: 2024-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -84,20 +84,48 @@ dependencies:
84
84
  - - "<"
85
85
  - !ruby/object:Gem::Version
86
86
  version: '4'
87
+ - !ruby/object:Gem::Dependency
88
+ name: rubocop
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: '1'
94
+ type: :development
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: '1'
101
+ - !ruby/object:Gem::Dependency
102
+ name: rubocop-rake
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - "~>"
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ type: :development
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - "~>"
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
87
115
  - !ruby/object:Gem::Dependency
88
116
  name: yard
89
117
  requirement: !ruby/object:Gem::Requirement
90
118
  requirements:
91
119
  - - "~>"
92
120
  - !ruby/object:Gem::Version
93
- version: 0.9.34
121
+ version: '0.9'
94
122
  type: :development
95
123
  prerelease: false
96
124
  version_requirements: !ruby/object:Gem::Requirement
97
125
  requirements:
98
126
  - - "~>"
99
127
  - !ruby/object:Gem::Version
100
- version: 0.9.34
128
+ version: '0.9'
101
129
  - !ruby/object:Gem::Dependency
102
130
  name: ecoportal-api
103
131
  requirement: !ruby/object:Gem::Requirement
@@ -105,6 +133,9 @@ dependencies:
105
133
  - - "~>"
106
134
  - !ruby/object:Gem::Version
107
135
  version: '0.10'
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: 0.10.5
108
139
  type: :runtime
109
140
  prerelease: false
110
141
  version_requirements: !ruby/object:Gem::Requirement
@@ -112,6 +143,9 @@ dependencies:
112
143
  - - "~>"
113
144
  - !ruby/object:Gem::Version
114
145
  version: '0.10'
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: 0.10.5
115
149
  - !ruby/object:Gem::Dependency
116
150
  name: mime-types
117
151
  requirement: !ruby/object:Gem::Requirement
@@ -134,9 +168,7 @@ dependencies:
134
168
  version: 3.5.2
135
169
  description:
136
170
  email:
137
- - rien@ecoportal.co.nz
138
171
  - oscar@ecoportal.co.nz
139
- - bozydar@ecoportal.co.nz
140
172
  executables: []
141
173
  extensions: []
142
174
  extra_rdoc_files: []
@@ -270,7 +302,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
270
302
  - !ruby/object:Gem::Version
271
303
  version: '0'
272
304
  requirements: []
273
- rubygems_version: 3.5.6
305
+ rubygems_version: 3.5.18
274
306
  signing_key:
275
307
  specification_version: 4
276
308
  summary: A collection of helpers for interacting with the ecoPortal MS's V2 API