ecoportal-api-v2 1.1.7 → 1.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +54 -15
- data/CHANGELOG.md +6 -3
- data/lib/ecoportal/api/common/content/array_model.rb +81 -78
- data/lib/ecoportal/api/common/content/class_helpers.rb +25 -26
- data/lib/ecoportal/api/common/content/collection_model.rb +76 -64
- data/lib/ecoportal/api/common/content/double_model.rb +105 -87
- data/lib/ecoportal/api/v2/page/component.rb +60 -64
- data/lib/ecoportal/api/v2/page/components.rb +9 -9
- data/lib/ecoportal/api/v2/page/force.rb +5 -6
- data/lib/ecoportal/api/v2/page.rb +13 -14
- data/lib/ecoportal/api/v2_version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70ba8da2cd5c6bd11498fb6cf8a40b04d121940c1693efc525372e3a584758f8
|
4
|
+
data.tar.gz: 2aa49af74223a5a03529fd3920714ff9b4f1dcbc636285c6b187acebe9b2e601
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75a8af0bc9495b4ba65688914eaf2ac94e4b08756581a3e6f193c390376ae6d905d08321ba8c8017675e1d2991ce1c699176f74c4c7b4b3b7aa91edbd8b37325
|
7
|
+
data.tar.gz: ea3368515e1fb001874e4e932902e063bb2e1cbf015cb352c2813313bb97abd80c446e5f9ab623fa11dbc0dc8e9c164c5b1947475d7a43c935da91ac34c9be22
|
data/.rubocop.yml
CHANGED
@@ -1,39 +1,70 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion: 2.
|
2
|
+
TargetRubyVersion: 2.7.8
|
3
3
|
Exclude:
|
4
4
|
- 'config/routes.rb'
|
5
|
+
NewCops: enable
|
5
6
|
|
6
|
-
Metrics/
|
7
|
-
|
8
|
-
Metrics/
|
9
|
-
|
10
|
-
Max: 50
|
7
|
+
Metrics/ClassLength:
|
8
|
+
Max: 500
|
9
|
+
Metrics/ModuleLength:
|
10
|
+
Max: 300
|
11
11
|
Metrics/MethodLength:
|
12
12
|
Max: 50
|
13
|
-
Metrics/ClassLength:
|
14
|
-
Max: 200
|
15
13
|
Metrics/AbcSize:
|
16
14
|
Max: 30
|
17
|
-
|
18
|
-
ParameterLists:
|
15
|
+
Metrics/ParameterLists:
|
19
16
|
Max: 5
|
20
17
|
CountKeywordArgs: false
|
18
|
+
Metrics/BlockLength:
|
19
|
+
CountAsOne: ['array', 'heredoc', 'method_call']
|
20
|
+
Max: 50
|
21
|
+
Metrics/CyclomaticComplexity:
|
22
|
+
Max: 30
|
23
|
+
Metrics/PerceivedComplexity:
|
24
|
+
Max: 30
|
21
25
|
|
22
|
-
Style/
|
26
|
+
Style/AccessorGrouping:
|
27
|
+
Enabled: false
|
28
|
+
Style/ConditionalAssignment:
|
29
|
+
Enabled: false
|
30
|
+
Style/BlockDelimiters:
|
31
|
+
BracesRequiredMethods: ['log']
|
32
|
+
Style/ClassAndModuleChildren:
|
23
33
|
Enabled: false
|
24
34
|
Style/FrozenStringLiteralComment:
|
25
35
|
Enabled: false
|
26
|
-
Style/
|
36
|
+
Style/StringLiterals:
|
27
37
|
Enabled: false
|
28
|
-
Style/
|
38
|
+
Style/StringLiteralsInInterpolation:
|
29
39
|
Enabled: false
|
30
40
|
Style/Documentation:
|
31
41
|
Enabled: false
|
32
|
-
Style/
|
42
|
+
Style/CommentedKeyword:
|
43
|
+
Enabled: false
|
44
|
+
Style/MultilineBlockChain:
|
33
45
|
Enabled: false
|
34
46
|
Style/AndOr:
|
35
47
|
Enabled: false
|
48
|
+
Style/Alias:
|
49
|
+
EnforcedStyle: prefer_alias_method
|
50
|
+
Style/FetchEnvVar:
|
51
|
+
Enabled: false
|
52
|
+
Style/RegexpLiteral:
|
53
|
+
EnforcedStyle: mixed
|
54
|
+
AllowInnerSlashes: true
|
36
55
|
|
56
|
+
Layout/HashAlignment:
|
57
|
+
EnforcedColonStyle: table
|
58
|
+
EnforcedHashRocketStyle: table
|
59
|
+
Layout/LeadingCommentSpace:
|
60
|
+
Enabled: false
|
61
|
+
AllowGemfileRubyComment: true
|
62
|
+
Layout/ParameterAlignment:
|
63
|
+
Enabled: false
|
64
|
+
Layout/MultilineMethodDefinitionBraceLayout:
|
65
|
+
EnforcedStyle: symmetrical
|
66
|
+
Layout/LineLength:
|
67
|
+
Enabled: true
|
37
68
|
Layout/SpaceInsideHashLiteralBraces:
|
38
69
|
Enabled: false
|
39
70
|
Layout/SpaceInsideBlockBraces:
|
@@ -42,14 +73,22 @@ Layout/SpaceAroundOperators:
|
|
42
73
|
Enabled: false
|
43
74
|
Layout/ExtraSpacing:
|
44
75
|
AllowForAlignment: true
|
76
|
+
AllowBeforeTrailingComments: true
|
45
77
|
Layout/AccessModifierIndentation:
|
46
78
|
EnforcedStyle: indent
|
47
79
|
Layout/DotPosition:
|
48
80
|
EnforcedStyle: trailing
|
49
81
|
Layout/MultilineMethodCallIndentation:
|
50
82
|
EnforcedStyle: indented
|
51
|
-
Layout/
|
83
|
+
Layout/FirstHashElementIndentation:
|
84
|
+
Enabled: false
|
85
|
+
Layout/EmptyLineAfterGuardClause:
|
52
86
|
Enabled: false
|
53
87
|
|
54
88
|
Naming/VariableNumber:
|
55
89
|
EnforcedStyle: snake_case
|
90
|
+
CheckSymbols: false
|
91
|
+
Naming/MethodParameterName:
|
92
|
+
AllowedNames: ['x', 'y', 'i', 'j', 'id', 'io']
|
93
|
+
Naming/RescuedExceptionsVariableName:
|
94
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
-
## [1.1.8] - 2024-03-
|
4
|
+
## [1.1.8] - 2024-03-23
|
5
5
|
|
6
|
-
### Added
|
7
6
|
### Changed
|
7
|
+
- A lot of code tidy up
|
8
|
+
|
8
9
|
### Fixed
|
10
|
+
- `Ecoportal::API::Common::Conent::CollectionModel`
|
11
|
+
- correct `item` `klass` resolution
|
9
12
|
|
10
|
-
## [1.1.7] - 2024-03-
|
13
|
+
## [1.1.7] - 2024-03-13
|
11
14
|
|
12
15
|
### Added
|
13
16
|
- `Ecoportal::API::Common::Concerns::Benchmarkable`
|
@@ -7,13 +7,9 @@ module Ecoportal
|
|
7
7
|
# - Its purpose is to handle an Array of basic objects (i.e. `Date`, `String`, `Number`)
|
8
8
|
class ArrayModel < Content::DoubleModel
|
9
9
|
class TypeMismatchedComparison < StandardError
|
10
|
-
def initialize
|
11
|
-
if this
|
12
|
-
|
13
|
-
end
|
14
|
-
if that
|
15
|
-
msg += " To object where 'order_matters: #{that.order_matters?}' and 'uniq: #{that.uniq?}'."
|
16
|
-
end
|
10
|
+
def initialize(this: nil, that: msg = "Trying to compare objects with different behavior.")
|
11
|
+
msg += " From object with 'order_matters: #{this.order_matters?}' and 'uniq: #{this.uniq?}'." if this
|
12
|
+
msg += " To object where 'order_matters: #{that.order_matters?}' and 'uniq: #{that.uniq?}'." if that
|
17
13
|
super(msg)
|
18
14
|
end
|
19
15
|
end
|
@@ -27,7 +23,8 @@ module Ecoportal
|
|
27
23
|
# @param b [ArrayModel]
|
28
24
|
# @return [Boolean] `true` if both elements have same behaviour
|
29
25
|
def same_type?(a, b)
|
30
|
-
|
26
|
+
msg = "To use this comparison both objects should be `ArrayModel`"
|
27
|
+
raise msg unless a.is_a?(ArrayModel) && b.is_a?(ArrayModel)
|
31
28
|
(a.order_matters? == b.order_matters?) && (a.uniq? == b.uniq?)
|
32
29
|
end
|
33
30
|
end
|
@@ -38,12 +35,25 @@ module Ecoportal
|
|
38
35
|
super(doc, parent: parent, key: key, read_only: read_only)
|
39
36
|
end
|
40
37
|
|
41
|
-
def order_matters
|
42
|
-
|
38
|
+
def order_matters?
|
39
|
+
self.class.order_matters
|
40
|
+
end
|
41
|
+
|
42
|
+
def uniq?
|
43
|
+
self.class.uniq
|
44
|
+
end
|
45
|
+
|
46
|
+
def length
|
47
|
+
count
|
48
|
+
end
|
43
49
|
|
44
|
-
def
|
45
|
-
|
46
|
-
|
50
|
+
def empty?
|
51
|
+
count&.zero?
|
52
|
+
end
|
53
|
+
|
54
|
+
def present?
|
55
|
+
count&.positive?
|
56
|
+
end
|
47
57
|
|
48
58
|
def each(&block)
|
49
59
|
return to_enum(:each) unless block
|
@@ -66,10 +76,10 @@ module Ecoportal
|
|
66
76
|
_items.slice(0..-1)
|
67
77
|
end
|
68
78
|
|
69
|
-
# @param
|
79
|
+
# @param other [Object, Array<Object>, ArrayModel] the value(s) of the new object
|
70
80
|
# @return [ArrayModel] a new object with the current class
|
71
|
-
def new_from(
|
72
|
-
self.class.new(into_a(
|
81
|
+
def new_from(other)
|
82
|
+
self.class.new(into_a(other))
|
73
83
|
end
|
74
84
|
|
75
85
|
# @return [ArrayModel] a copy of the current object
|
@@ -93,28 +103,28 @@ module Ecoportal
|
|
93
103
|
# @param pos [Integer] the position of the element
|
94
104
|
# @param value [String, Date, Number] the element
|
95
105
|
# @return [Date, String, Number]
|
96
|
-
def []=(
|
106
|
+
def []=(pos, value)
|
97
107
|
_items[pos] = value
|
98
108
|
on_change
|
99
109
|
self[pos]
|
100
110
|
end
|
101
111
|
|
102
112
|
# Compares with an `Array` or another `ArrayModel`
|
103
|
-
# @param
|
104
|
-
def ==(
|
105
|
-
return true
|
106
|
-
return false unless (
|
107
|
-
|
113
|
+
# @param other [ArrayModel, Array]
|
114
|
+
def ==(other)
|
115
|
+
return true if equal?(other)
|
116
|
+
return false unless (other.class == self.class) || other.is_a?(Array)
|
117
|
+
|
118
|
+
case other
|
108
119
|
when Array
|
109
|
-
self == new_from(
|
120
|
+
self == new_from(other)
|
110
121
|
when ArrayModel
|
111
|
-
|
112
|
-
raise TypeMismatchedComparison.new(this: self, that: a) unless self.class.same_type?(self, a)
|
122
|
+
raise TypeMismatchedComparison.new(this: self, that: other) unless self.class.same_type?(self, other)
|
113
123
|
|
114
|
-
if
|
115
|
-
_items ==
|
124
|
+
if order_matters?
|
125
|
+
_items == other.to_a
|
116
126
|
else
|
117
|
-
(_items -
|
127
|
+
(_items - other.to_a).empty? && (other.to_a - _items).empty?
|
118
128
|
end
|
119
129
|
end
|
120
130
|
end
|
@@ -154,11 +164,10 @@ module Ecoportal
|
|
154
164
|
end
|
155
165
|
|
156
166
|
# Resets the `Array` by keeping its reference and adds the value(s)
|
157
|
-
# @param
|
158
|
-
|
159
|
-
def <(values)
|
167
|
+
# @param other [Object, Array<Object>, ArrayModel] the value(s) to be added
|
168
|
+
def <(other)
|
160
169
|
_items.clear
|
161
|
-
self <<
|
170
|
+
self << other
|
162
171
|
end
|
163
172
|
|
164
173
|
# Clears the `Array` keeping its reference
|
@@ -169,25 +178,25 @@ module Ecoportal
|
|
169
178
|
end
|
170
179
|
|
171
180
|
# Concat to new
|
172
|
-
def +(
|
173
|
-
new_from(
|
181
|
+
def +(other)
|
182
|
+
new_from(to_a + into_a(other))
|
174
183
|
end
|
175
184
|
|
176
185
|
# Join
|
177
|
-
# @param
|
186
|
+
# @param other [Object, Array<Object>, ArrayModel] the value(s) to be joined
|
178
187
|
# @return [ArrayModel] a new object instance with the intersection done
|
179
|
-
def |(
|
180
|
-
|
181
|
-
new_from(to_a +
|
188
|
+
def |(other)
|
189
|
+
oth = new_from(other) - self
|
190
|
+
new_from(to_a + oth.to_a)
|
182
191
|
end
|
183
192
|
|
184
193
|
# Intersect
|
185
|
-
# @param
|
194
|
+
# @param other [Object, Array<Object>, ArrayModel] the value(s) to be deleted
|
186
195
|
# @return [ArrayModel] a new object instance with the intersection done
|
187
|
-
def &(
|
188
|
-
|
189
|
-
|
190
|
-
delta.delete!(*into_a(
|
196
|
+
def &(other)
|
197
|
+
dup.tap do |out|
|
198
|
+
dup.tap do |delta|
|
199
|
+
delta.delete!(*into_a(other))
|
191
200
|
out.delete!(*into_a(delta))
|
192
201
|
end
|
193
202
|
end
|
@@ -196,9 +205,9 @@ module Ecoportal
|
|
196
205
|
# Subtract
|
197
206
|
# @param value [Object, Array<Object>, ArrayModel] the value(s) to be deleted
|
198
207
|
# @return [ArrayModel] a **copy** of the object with the elements subtracted
|
199
|
-
def -(
|
200
|
-
|
201
|
-
copy.delete!(*into_a(
|
208
|
+
def -(other)
|
209
|
+
dup.tap do |copy|
|
210
|
+
copy.delete!(*into_a(other))
|
202
211
|
end
|
203
212
|
end
|
204
213
|
|
@@ -206,7 +215,7 @@ module Ecoportal
|
|
206
215
|
def delete!(*values)
|
207
216
|
values.map do |v|
|
208
217
|
deletion!(v)
|
209
|
-
end.tap do |
|
218
|
+
end.tap do |_r|
|
210
219
|
on_change
|
211
220
|
end
|
212
221
|
end
|
@@ -216,43 +225,41 @@ module Ecoportal
|
|
216
225
|
# @param val1 [Object] the first value to swap
|
217
226
|
# @param val2 [Object] the second value to swap
|
218
227
|
# @return [Integer] the new of `value1`, `nil` if it wasn't moved
|
219
|
-
def swap(
|
220
|
-
index(
|
221
|
-
if dest && pos = index(
|
222
|
-
_items[dest] =
|
223
|
-
_items[pos] =
|
228
|
+
def swap(val_1, val_2)
|
229
|
+
index(val_2).tap do |dest|
|
230
|
+
if dest && (pos = index(val_1))
|
231
|
+
_items[dest] = val_1
|
232
|
+
_items[pos] = val_2
|
224
233
|
end
|
225
234
|
end
|
226
235
|
end
|
227
236
|
|
228
237
|
def insert_one(value, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
|
229
|
-
|
230
|
-
return
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
238
|
+
idx = index(value)
|
239
|
+
return idx if idx && uniq?
|
240
|
+
|
241
|
+
pos =
|
242
|
+
if used_param?(pos) && pos
|
243
|
+
pos
|
244
|
+
elsif used_param?(before) && before
|
245
|
+
index(before)
|
246
|
+
elsif used_param?(after) && after
|
247
|
+
if (idx = index(after)) then idx + 1 end
|
248
|
+
end
|
239
249
|
|
250
|
+
# use last position as default
|
240
251
|
pos ||= length
|
241
|
-
pos.tap do |
|
252
|
+
pos.tap do |_i|
|
242
253
|
_items.insert(pos, value)
|
243
254
|
on_change
|
244
255
|
end
|
245
256
|
end
|
246
257
|
|
247
258
|
# TODO
|
248
|
-
def move(value, pos: NOT_USED,
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
on_change
|
253
|
-
end
|
254
|
-
pos
|
255
|
-
end
|
259
|
+
def move(value, pos: NOT_USED, _before: NOT_USED, _after: NOT_USED)
|
260
|
+
return unless (idx = index(value))
|
261
|
+
on_change unless idx == pos
|
262
|
+
pos
|
256
263
|
end
|
257
264
|
|
258
265
|
protected
|
@@ -270,13 +277,9 @@ module Ecoportal
|
|
270
277
|
end
|
271
278
|
|
272
279
|
def deletion!(value)
|
273
|
-
if
|
274
|
-
|
275
|
-
|
276
|
-
end
|
277
|
-
else
|
278
|
-
_items.delete(value)
|
279
|
-
end
|
280
|
+
return _items.delete(value) if uniq?
|
281
|
+
return unless (idx = _items.index(value))
|
282
|
+
_items.slice!(idx)
|
280
283
|
end
|
281
284
|
end
|
282
285
|
end
|
@@ -5,7 +5,7 @@ module Ecoportal
|
|
5
5
|
module Content
|
6
6
|
module ClassHelpers
|
7
7
|
include Common::BaseClass
|
8
|
-
NOT_USED = "no_used!"
|
8
|
+
NOT_USED = "no_used!".freeze
|
9
9
|
|
10
10
|
# Class resolver
|
11
11
|
# @note it caches the resolved `klass`es
|
@@ -18,21 +18,21 @@ module Ecoportal
|
|
18
18
|
@resolved ||= {}
|
19
19
|
@resolved[klass] ||=
|
20
20
|
case klass
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
21
|
+
when Class
|
22
|
+
klass
|
23
|
+
when String
|
24
|
+
begin
|
25
|
+
Kernel.const_get(klass)
|
26
|
+
rescue NameError
|
27
|
+
raise if exception
|
28
|
+
end
|
29
|
+
when Symbol
|
30
|
+
source_class.resolve_class(source_class.send(klass))
|
31
|
+
when Hash
|
32
|
+
referrer, referred = klass.first
|
33
|
+
resolve_class(referred, source_class: referrer, exception: exception)
|
34
|
+
else
|
35
|
+
raise "Unknown class: #{klass}" if exception
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -41,11 +41,11 @@ module Ecoportal
|
|
41
41
|
# @param key [String, Symbol] to be normalized
|
42
42
|
# @return [String] a correct constant name
|
43
43
|
def to_constant(key)
|
44
|
-
|
44
|
+
key.to_s.strip.split(/::/).compact.map do |str|
|
45
45
|
str.slice(0).upcase + str.slice(1..-1)
|
46
|
-
end.join
|
46
|
+
end.join.split(/[\-\_ :]+/i).compact.map do |str|
|
47
47
|
str.slice(0).upcase + str.slice(1..-1)
|
48
|
-
end.join
|
48
|
+
end.join
|
49
49
|
end
|
50
50
|
|
51
51
|
# Helper to create an instance variable `name`
|
@@ -60,7 +60,7 @@ module Ecoportal
|
|
60
60
|
# Generates random ids in hexadecimal to use in class name generation.
|
61
61
|
# @param len [Integeter] length of the `uid`
|
62
62
|
# @return [String] a random unique id of length `len`
|
63
|
-
def uid(len = 8)
|
63
|
+
def uid(len = 8)
|
64
64
|
SecureRandom.hex(len/2)
|
65
65
|
end
|
66
66
|
|
@@ -72,8 +72,8 @@ module Ecoportal
|
|
72
72
|
# @yieldparam child_class [Class] the new class
|
73
73
|
# @return [Class] the new generated class
|
74
74
|
def new_class(name = "Child#{uid}", inherits: self, namespace: inherits)
|
75
|
-
name
|
76
|
-
class_name
|
75
|
+
name = name.to_s.to_sym.freeze
|
76
|
+
class_name = to_constant(name)
|
77
77
|
|
78
78
|
unless target_class = resolve_class("#{namespace}::#{class_name}", exception: false)
|
79
79
|
target_class = Class.new(inherits)
|
@@ -92,19 +92,17 @@ module Ecoportal
|
|
92
92
|
# @return
|
93
93
|
def to_time(value, exception: true)
|
94
94
|
case value
|
95
|
-
when NilClass
|
95
|
+
when Time, NilClass
|
96
96
|
value
|
97
97
|
when String
|
98
98
|
begin
|
99
99
|
Time.parse(value)
|
100
|
-
rescue ArgumentArgument
|
100
|
+
rescue ArgumentArgument
|
101
101
|
raise if exception
|
102
102
|
nil
|
103
103
|
end
|
104
104
|
when Date
|
105
105
|
Time.parse(value.to_s)
|
106
|
-
when Time
|
107
|
-
value
|
108
106
|
else
|
109
107
|
to_time(value.to_s) if value.respond_to?(:to_s)
|
110
108
|
end
|
@@ -147,6 +145,7 @@ module Ecoportal
|
|
147
145
|
# - mutating methods would reflect the changes on other classes as well
|
148
146
|
# - therefore, `freeze` will be called on the values that are inherited.
|
149
147
|
def inherited(subclass)
|
148
|
+
super
|
150
149
|
inheritable_class_vars.each do |var|
|
151
150
|
instance_var = instance_variable_name(var)
|
152
151
|
value = instance_variable_get(instance_var)
|