forest_admin_datasource_active_record 1.46.1 → 1.46.2
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: 519919e6c2c87ab7f22e619760a095bd246354e7ea40a9c28d0ffedf732b39ce
|
|
4
|
+
data.tar.gz: 89830403c6a059b62e4a79243eb64704c2ec81337c2a6e44186c30eb14fca5b4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4877050b372860ea1c992a05920fc8d548c8bdea968b3627cccda8a77f333744c2327aec0b27e81cfe4e8ade643cf0bb9de80ed7578ef4a4cd237c8e36740727
|
|
7
|
+
data.tar.gz: a377774b938fe9b3bb2499a4e0a6b45c638ab8e1407391e03d4189e6cabf5243f9400160f321ffbbc91ae3047b80e00461f632d978e46724c7a868fc743279ee
|
|
@@ -57,92 +57,84 @@ module ForestAdminDatasourceActiveRecord
|
|
|
57
57
|
@query
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
-
def apply_condition_tree(condition_tree
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
condition_tree.conditions.each do |condition|
|
|
64
|
-
@query = apply_condition_tree(condition, aggregator)
|
|
65
|
-
@query = @query.send(aggregator, @query)
|
|
66
|
-
end
|
|
60
|
+
def apply_condition_tree(condition_tree)
|
|
61
|
+
query_aggregator(:and, condition_relation(condition_tree))
|
|
62
|
+
end
|
|
67
63
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
# Each branch is built as its own relation so ActiveRecord groups it: chaining every leaf onto
|
|
65
|
+
# @query compiled And[a, Or[x, y]] as `a OR x OR y`.
|
|
66
|
+
def condition_relation(condition_tree)
|
|
67
|
+
return leaf_relation(condition_tree) unless condition_tree.is_a?(Nodes::ConditionTreeBranch)
|
|
68
|
+
|
|
69
|
+
aggregator = condition_tree.aggregator.downcase.to_sym
|
|
70
|
+
relations = condition_tree.conditions.map { |condition| condition_relation(condition) }
|
|
71
|
+
return @collection.model.where(Arel.sql(aggregator == :or ? '1 = 0' : '1 = 1')) if relations.empty?
|
|
72
|
+
|
|
73
|
+
relations.reduce { |combined, relation| combined.send(aggregator, relation) }
|
|
72
74
|
end
|
|
73
75
|
|
|
74
|
-
def
|
|
76
|
+
def leaf_relation(condition_tree)
|
|
75
77
|
resolved = resolve_field(condition_tree.field)
|
|
76
78
|
field = resolved[:formatted]
|
|
77
79
|
arel_attr = resolved[:arel_attr]
|
|
78
80
|
value = condition_tree.value
|
|
79
|
-
aggregator = aggregator.to_sym
|
|
80
81
|
|
|
81
82
|
case condition_tree.operator
|
|
82
83
|
when Operators::PRESENT
|
|
83
84
|
field_schema = ForestAdminDatasourceToolkit::Utils::Collection.get_field_schema(@collection,
|
|
84
85
|
condition_tree.field)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
if field_schema.column_type == 'String'
|
|
87
|
+
@collection.model.where.not({ field => [nil, ''] })
|
|
88
|
+
else
|
|
89
|
+
@collection.model.where.not({ field => nil })
|
|
90
|
+
end
|
|
90
91
|
when Operators::BLANK
|
|
91
92
|
field_schema = ForestAdminDatasourceToolkit::Utils::Collection.get_field_schema(@collection,
|
|
92
93
|
condition_tree.field)
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
if field_schema.column_type == 'String'
|
|
95
|
+
@collection.model.where({ field => [nil, ''] })
|
|
96
|
+
else
|
|
97
|
+
@collection.model.where({ field => nil })
|
|
98
|
+
end
|
|
98
99
|
when Operators::MISSING
|
|
99
|
-
@
|
|
100
|
+
@collection.model.where({ field => nil })
|
|
100
101
|
when Operators::EQUAL, Operators::IN
|
|
101
|
-
@
|
|
102
|
+
@collection.model.where({ field => value })
|
|
102
103
|
when Operators::NOT_EQUAL, Operators::NOT_IN
|
|
103
|
-
@
|
|
104
|
+
@collection.model.where.not({ field => value })
|
|
104
105
|
when Operators::GREATER_THAN
|
|
105
|
-
|
|
106
|
+
build_comparison_query(condition_tree.field, arel_attr, value, :gt)
|
|
106
107
|
when Operators::GREATER_THAN_OR_EQUAL
|
|
107
|
-
|
|
108
|
+
build_comparison_query(condition_tree.field, arel_attr, value, :gteq)
|
|
108
109
|
when Operators::LESS_THAN
|
|
109
|
-
|
|
110
|
+
build_comparison_query(condition_tree.field, arel_attr, value, :lt)
|
|
110
111
|
when Operators::LESS_THAN_OR_EQUAL
|
|
111
|
-
|
|
112
|
+
build_comparison_query(condition_tree.field, arel_attr, value, :lteq)
|
|
112
113
|
when Operators::CONTAINS
|
|
113
|
-
@
|
|
114
|
-
@collection.model.where(arel_attr.matches("%#{value}%")))
|
|
114
|
+
@collection.model.where(arel_attr.matches("%#{value}%"))
|
|
115
115
|
when Operators::I_CONTAINS
|
|
116
116
|
lower_field = Arel::Nodes::NamedFunction.new('LOWER', [arel_attr])
|
|
117
|
-
@
|
|
118
|
-
@collection.model.where(lower_field.matches("%#{value.to_s.downcase}%")))
|
|
117
|
+
@collection.model.where(lower_field.matches("%#{value.to_s.downcase}%"))
|
|
119
118
|
when Operators::NOT_CONTAINS
|
|
120
|
-
@
|
|
121
|
-
@collection.model.where.not(arel_attr.matches("%#{value}%")))
|
|
119
|
+
@collection.model.where.not(arel_attr.matches("%#{value}%"))
|
|
122
120
|
when Operators::NOT_I_CONTAINS
|
|
123
121
|
lower_field = Arel::Nodes::NamedFunction.new('LOWER', [arel_attr])
|
|
124
|
-
@
|
|
125
|
-
@collection.model.where.not(lower_field.matches("%#{value.to_s.downcase}%")))
|
|
122
|
+
@collection.model.where.not(lower_field.matches("%#{value.to_s.downcase}%"))
|
|
126
123
|
when Operators::STARTS_WITH
|
|
127
|
-
@
|
|
128
|
-
@collection.model.where(arel_attr.matches("#{value}%")))
|
|
124
|
+
@collection.model.where(arel_attr.matches("#{value}%"))
|
|
129
125
|
when Operators::I_STARTS_WITH
|
|
130
126
|
lower_field = Arel::Nodes::NamedFunction.new('LOWER', [arel_attr])
|
|
131
|
-
@
|
|
132
|
-
@collection.model.where(lower_field.matches("#{value.to_s.downcase}%")))
|
|
127
|
+
@collection.model.where(lower_field.matches("#{value.to_s.downcase}%"))
|
|
133
128
|
when Operators::ENDS_WITH
|
|
134
|
-
@
|
|
135
|
-
@collection.model.where(arel_attr.matches("%#{value}")))
|
|
129
|
+
@collection.model.where(arel_attr.matches("%#{value}"))
|
|
136
130
|
when Operators::I_ENDS_WITH
|
|
137
131
|
lower_field = Arel::Nodes::NamedFunction.new('LOWER', [arel_attr])
|
|
138
|
-
@
|
|
139
|
-
@collection.model.where(lower_field.matches("%#{value.to_s.downcase}")))
|
|
132
|
+
@collection.model.where(lower_field.matches("%#{value.to_s.downcase}"))
|
|
140
133
|
when Operators::LIKE
|
|
141
|
-
@
|
|
134
|
+
@collection.model.where(arel_attr.matches(value))
|
|
142
135
|
when Operators::I_LIKE
|
|
143
136
|
lower_field = Arel::Nodes::NamedFunction.new('LOWER', [arel_attr])
|
|
144
|
-
@
|
|
145
|
-
@collection.model.where(lower_field.matches(value.to_s.downcase)))
|
|
137
|
+
@collection.model.where(lower_field.matches(value.to_s.downcase))
|
|
146
138
|
when Operators::MATCH
|
|
147
139
|
# Match operator supports:
|
|
148
140
|
# - Regexp objects from pattern transformations: Regexp.new("pattern")
|
|
@@ -167,18 +159,16 @@ module ForestAdminDatasourceActiveRecord
|
|
|
167
159
|
raise ArgumentError, "Match operator is not supported for database adapter '#{adapter_name}'"
|
|
168
160
|
end
|
|
169
161
|
|
|
170
|
-
@
|
|
162
|
+
@collection.model.where(regex_clause, pattern)
|
|
171
163
|
when Operators::INCLUDES_ALL
|
|
172
|
-
@
|
|
164
|
+
@collection.model.where(arel_attr.matches_all(value))
|
|
173
165
|
when Operators::SHORTER_THAN
|
|
174
166
|
length_func = Arel::Nodes::NamedFunction.new('LENGTH', [arel_attr])
|
|
175
|
-
@
|
|
167
|
+
@collection.model.where(length_func.lt(value))
|
|
176
168
|
when Operators::LONGER_THAN
|
|
177
169
|
length_func = Arel::Nodes::NamedFunction.new('LENGTH', [arel_attr])
|
|
178
|
-
@
|
|
170
|
+
@collection.model.where(length_func.gt(value))
|
|
179
171
|
end
|
|
180
|
-
|
|
181
|
-
@query
|
|
182
172
|
end
|
|
183
173
|
|
|
184
174
|
def build_select(collection, projection)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: forest_admin_datasource_active_record
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.46.
|
|
4
|
+
version: 1.46.2
|
|
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: 2026-10-
|
|
12
|
+
date: 2026-10-20 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: activerecord
|
|
@@ -115,14 +115,14 @@ dependencies:
|
|
|
115
115
|
requirements:
|
|
116
116
|
- - ">="
|
|
117
117
|
- !ruby/object:Gem::Version
|
|
118
|
-
version: 1.46.
|
|
118
|
+
version: 1.46.2
|
|
119
119
|
type: :runtime
|
|
120
120
|
prerelease: false
|
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
|
122
122
|
requirements:
|
|
123
123
|
- - ">="
|
|
124
124
|
- !ruby/object:Gem::Version
|
|
125
|
-
version: 1.46.
|
|
125
|
+
version: 1.46.2
|
|
126
126
|
- !ruby/object:Gem::Dependency
|
|
127
127
|
name: logger
|
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|