forest_admin_agent 1.0.0.pre.beta.52 → 1.0.0.pre.beta.53
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: 58f20bfe5d2243e06eb35a20c5ec51e6610d81d92272f782eaace19112314a21
|
4
|
+
data.tar.gz: 85cfe4e3217e0ca0a444ab642dc9d369a6a5843b7ca947ecd4ff86e9b0aca5dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ca98b9bfcc25c40c15c822b745bbe571ece3499bfc2b68c4ecb682fecfb66e0ef3a525613dcf30ebae432cbf0e9e199891524f3d6df19a92ccdc121203da919
|
7
|
+
data.tar.gz: 6f11399dc1a82b75b15e79962704ec54b3e0c33bad6eab51285cd22f3a871de89b625af88a6e2e5b458c7fb999a98c3f266fb1b1bea84972072f963b1f6244c8
|
@@ -53,8 +53,11 @@ module ForestAdminAgent
|
|
53
53
|
def self.convert_validation_list(column)
|
54
54
|
return [] if column.validations.empty?
|
55
55
|
|
56
|
-
rules = column.validations.
|
57
|
-
remove_duplicates_in_place(rules)
|
56
|
+
rules = column.validations.map { |rule| simplify_rule(column.column_type, rule) }
|
57
|
+
remove_duplicates_in_place(rules)
|
58
|
+
|
59
|
+
rules.filter { |rule| rule.is_a?(Hash) && rule.key?(:operator) }
|
60
|
+
.map { |rule| SUPPORTED[rule[:operator]].call(rule) }
|
58
61
|
end
|
59
62
|
|
60
63
|
def self.simplify_rule(column_type, rule)
|
@@ -74,11 +77,16 @@ module ForestAdminAgent
|
|
74
77
|
timezone = 'Europe/Paris' # we're sending the schema => use random tz
|
75
78
|
tree = ConditionTreeEquivalent.get_equivalent_tree(leaf, operators, column_type, timezone)
|
76
79
|
|
77
|
-
if tree.is_a? Nodes::ConditionTreeLeaf
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
80
|
+
conditions = if tree.is_a? Nodes::ConditionTreeLeaf
|
81
|
+
[tree]
|
82
|
+
else
|
83
|
+
tree.conditions
|
84
|
+
end
|
85
|
+
|
86
|
+
return conditions.filter { |c| c.is_a?(Nodes::ConditionTreeLeaf) }
|
87
|
+
.filter { |c| c.operator != Operators::EQUAL && c.operator != Operators::NOT_EQUAL }
|
88
|
+
.map { |c| simplify_rule(column_type, operator: c.operator, value: c.value) }
|
89
|
+
.first
|
82
90
|
rescue StandardError
|
83
91
|
# Just ignore errors, they mean that the operator is not supported by the frontend
|
84
92
|
# and that we don't have an automatic conversion for it.
|
@@ -91,36 +99,44 @@ module ForestAdminAgent
|
|
91
99
|
[]
|
92
100
|
end
|
93
101
|
|
94
|
-
# The frontend crashes when it receives multiple rules of the same type.
|
95
|
-
# This method merges the rules which can be merged and drops the others.
|
96
102
|
def self.remove_duplicates_in_place(rules)
|
97
103
|
used = {}
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
104
|
+
|
105
|
+
i = 0
|
106
|
+
while i < rules.length
|
107
|
+
rule = rules[i]
|
108
|
+
if rule.is_a?(Hash) && rule.key?(:operator)
|
109
|
+
if used.key?(rule[:operator])
|
110
|
+
existing_rule = rules[used[rule[:operator]]]
|
111
|
+
new_rule = rules.delete_at(i)
|
112
|
+
|
113
|
+
merge_into(existing_rule, new_rule)
|
114
|
+
# Adjust the index to account for the removed element
|
115
|
+
i -= 1
|
116
|
+
else
|
117
|
+
used[rule[:operator]] = i
|
118
|
+
end
|
106
119
|
end
|
120
|
+
i += 1
|
107
121
|
end
|
108
|
-
|
109
|
-
rules
|
110
122
|
end
|
111
123
|
|
112
|
-
|
113
|
-
|
124
|
+
# rubocop:disable Style/EmptyElse
|
125
|
+
def self.merge_into(rule, new_rule)
|
126
|
+
case rule[:operator]
|
127
|
+
when Operators::GREATER_THAN, Operators::AFTER, Operators::LONGER_THAN
|
114
128
|
rule[:value] = [rule[:value], new_rule[:value]].max
|
115
|
-
|
129
|
+
when Operators::LESS_THAN, Operators::BEFORE, Operators::SHORTER_THAN
|
116
130
|
rule[:value] = [rule[:value], new_rule[:value]].min
|
117
|
-
|
118
|
-
|
131
|
+
when Operators::MATCH
|
132
|
+
regex = rule[:value].gsub(/\W/, '')
|
133
|
+
new_regex = new_rule[:value].gsub(/\W/, '')
|
134
|
+
rule[:value] = "/^(?=#{regex})(?=#{new_regex}).*$/i"
|
135
|
+
else
|
136
|
+
# Ignore the rules that we can't deduplicate (we could log a warning here).
|
119
137
|
end
|
120
|
-
# else Ignore the rules that we can't deduplicate (we could log a warning here).
|
121
|
-
|
122
|
-
rule
|
123
138
|
end
|
139
|
+
# rubocop:enable Style/EmptyElse
|
124
140
|
end
|
125
141
|
end
|
126
142
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forest_admin_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.pre.beta.
|
4
|
+
version: 1.0.0.pre.beta.53
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthieu
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-06-
|
12
|
+
date: 2024-06-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|