madmin 3.1.1 → 3.1.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 +4 -4
- data/lib/madmin/filter.rb +21 -4
- data/lib/madmin/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dde4d963db323d7d26197c454095beed2eff86ff40dcd9359e85ee480dd3bc13
|
|
4
|
+
data.tar.gz: 68566f86e2163ce2b7bf2fd12f6289d786fa118639936eff1aeef5f84feea616
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0c2206a2935ec06380389dbca3109acabf2a3f0af8d84105d964b9551bde50c30c8746403aa718b0acd9e397efecb7fe70e74f9b8704d5a2c3d7d8474898305f
|
|
7
|
+
data.tar.gz: eb2128311c6fd923d69f3d58955e7c9e0bdf322a8949532fc156ec8fec6bba4ab6afd6771d4b06df584a3939ef67ba5879dad16da75611d37816857b92d9582f
|
data/lib/madmin/filter.rb
CHANGED
|
@@ -12,6 +12,9 @@ module Madmin
|
|
|
12
12
|
|
|
13
13
|
WITHOUT_VALUE = %w[blank present true false].freeze
|
|
14
14
|
|
|
15
|
+
# Operators that match the value as text instead of casting it to the column's type
|
|
16
|
+
MATCHING_OPERATORS = %w[contains starts_with].freeze
|
|
17
|
+
|
|
15
18
|
attr_reader :field, :operator, :value
|
|
16
19
|
|
|
17
20
|
# Skips conditions for unknown columns or operators, and values that don't
|
|
@@ -45,15 +48,16 @@ module Madmin
|
|
|
45
48
|
end
|
|
46
49
|
|
|
47
50
|
def valid?
|
|
48
|
-
field&.filter_type.present? && OPERATORS[type].include?(operator) &&
|
|
51
|
+
field&.filter_type.present? && OPERATORS[type].include?(operator) &&
|
|
52
|
+
(!value? || (matching_operator? ? value.present? : typed_value.present?))
|
|
49
53
|
end
|
|
50
54
|
|
|
51
55
|
def apply(scope)
|
|
52
56
|
attribute = scope.arel_table[column]
|
|
53
57
|
|
|
54
58
|
case operator
|
|
55
|
-
when "contains" then scope.where(attribute.matches("%#{escaped_value}%"))
|
|
56
|
-
when "starts_with" then scope.where(attribute.matches("#{escaped_value}%"))
|
|
59
|
+
when "contains" then scope.where(as_text(attribute).matches("%#{escaped_value}%"))
|
|
60
|
+
when "starts_with" then scope.where(as_text(attribute).matches("#{escaped_value}%"))
|
|
57
61
|
when "eq" then scope.where(column => typed_value)
|
|
58
62
|
when "gt" then scope.where(attribute.gt(typed_value))
|
|
59
63
|
when "gte" then scope.where(attribute.gteq(typed_value))
|
|
@@ -85,12 +89,25 @@ module Madmin
|
|
|
85
89
|
(type == :array) ? attribute_type.subtype : attribute_type
|
|
86
90
|
end
|
|
87
91
|
|
|
92
|
+
def matching_operator?
|
|
93
|
+
MATCHING_OPERATORS.include?(operator)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def uuid?
|
|
97
|
+
value_type.type == :uuid
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def as_text(attribute)
|
|
101
|
+
uuid? ? Arel::Nodes::NamedFunction.new("CAST", [attribute.as("CHAR(36)")]) : attribute
|
|
102
|
+
end
|
|
103
|
+
|
|
88
104
|
def escaped_value
|
|
89
105
|
field.model.sanitize_sql_like(value)
|
|
90
106
|
end
|
|
91
107
|
|
|
92
108
|
def blank_values
|
|
93
|
-
|
|
109
|
+
# UUIDs cast "" to NULL, which would match nothing
|
|
110
|
+
(type == :string && !uuid?) ? [nil, ""] : nil
|
|
94
111
|
end
|
|
95
112
|
end
|
|
96
113
|
end
|
data/lib/madmin/version.rb
CHANGED