mensa 0.7.2 → 0.7.4

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: ca5c6f3fab08895527058f4cbb70a55608297da85a234c2476d120be6de13882
4
- data.tar.gz: f09da64e3c8dfaaf1917e1097845171aa29fab13c18285d3802278d5a7d8bfc9
3
+ metadata.gz: ab3722840d818b5e39cac9b51fe13230d93fc1bcc3cfa61ecebedbff2f1fdc52
4
+ data.tar.gz: cb5a23038d098bcde99caf7db0764288c82e882c31416a18875ffda4916dc12f
5
5
  SHA512:
6
- metadata.gz: 2f9ff2a45fd5d5784a31ee7e96d45b683bc16aecb53947eb6a942f5764d175fcbbc16303103ad3c46f71a571da8c5a8b5e8af9fa82000fdd8bbd025694108263
7
- data.tar.gz: 9948a29ea8daee96c71466b33d3e63e4a7dd20496247edf36740c779cf2b2743fbfdedf92f03a391abe5d43544aa32f25825b340b6fb8a8f471bb66432107dda
6
+ metadata.gz: 32c0a1ada80a403d35e9400e10273f6122c445e7c71ee2cdd4bc4492f9c11881de46f1020bd4db7591f97a3ec8a16c89012458f89a77e1a65e223800298c95f0
7
+ data.tar.gz: 0a5532668ef39a57ff4b9118d2940fb63566bd41d287d28e579f4b729c0e811eff494e95a9035f53c97f6f4f12d7758295ba7d6ff7ffbf1956a238e201737273
data/.shipkit.yml CHANGED
@@ -1,2 +1,2 @@
1
1
  ---
2
- previous_version: 0.7.1
2
+ previous_version: 0.7.3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.4
4
+
5
+ - **Behaviour change:** the `matches` and `does_not_match` filters now do a
6
+ case-insensitive "contains" (`ILIKE '%value%'`), the same way search does.
7
+ Before, they passed the value to `LIKE` as it was, so `matches "LLC"` only
8
+ found rows that were exactly `LLC`. The value is taken literally, so saved
9
+ views that relied on typing `%` or `_` wildcards now match a literal `%` or
10
+ `_`. `does_not_match` now also returns rows where the column is NULL.
11
+ Attributes without a `type` are cast to text for the comparison.
12
+ - Search leaves out internal columns. They aren't shown, so a row found
13
+ through one looked like it didn't match.
14
+
3
15
  ## 0.7.2
4
16
 
5
17
  - The verifier's report only lists failures and warnings. `-v`/`--verbose` (or
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mensa (0.7.1)
4
+ mensa (0.7.3)
5
5
  csv
6
6
  importmap-rails
7
7
  pagy (>= 43)
data/README.md CHANGED
@@ -187,6 +187,11 @@ The operators are `is`, `isnt`, `matches`, `does_not_match`, `gt`, `gteq`, `lt`,
187
187
  | boolean, uuid, enums and other types | `is`, `isnt` |
188
188
  | jsonb, json | none (json also has no `is_duplicate`) |
189
189
 
190
+ `matches` finds rows where the column contains the value anywhere, ignoring case
191
+ (`ILIKE '%value%'`), and `does_not_match` finds the others, including rows where the
192
+ column is empty (NULL). The value is taken literally: `%`, `_` and `\` are matched as
193
+ characters, not as wildcards. A blank value matches only empty strings.
194
+
190
195
  `matches` and `does_not_match` are left out when the filter has a `collection`, and
191
196
  `is_current` is only offered when `Current` has a method named after the column.
192
197
 
@@ -14,7 +14,7 @@ module Mensa
14
14
  config_reader :multiple
15
15
  config_reader :having?
16
16
 
17
- # Types that LIKE works on, nil is an attribute without a type
17
+ # Types that ILIKE works on, nil is an attribute without a type
18
18
  TEXT_TYPES = [:string, :text, :citext, nil].freeze
19
19
  # Types with a meaningful order, for gt, gteq, lt and lteq
20
20
  RANGE_TYPES = %i[integer bigint float decimal money date datetime timestamp timestamptz time interval].freeze
@@ -139,9 +139,12 @@ module Mensa
139
139
  hash[:value] = Current.public_send(column.name)
140
140
  "#{col} = :value"
141
141
  when :matches
142
- "#{col} LIKE :value"
142
+ hash[:value] = contains_pattern(hash[:value])
143
+ "#{text_col(col)} ILIKE :value"
143
144
  when :does_not_match
144
- "#{col} NOT LIKE :value"
145
+ # Rows without a value don't contain it either
146
+ hash[:value] = contains_pattern(hash[:value])
147
+ "(#{col} IS NULL OR #{text_col(col)} NOT ILIKE :value)"
145
148
  when :is
146
149
  hash[:value].is_a?(Array) ? "#{col} IN (:value)" : "#{col} = :value"
147
150
  when :isnt
@@ -280,6 +283,23 @@ module Mensa
280
283
  record_scope.having("#{column_sql} IN (#{duplicate_values_scope.to_sql})")
281
284
  end
282
285
 
286
+ # A case-insensitive "contains" pattern, with %, _ and \ in the value
287
+ # matched literally. A blank value is compared as it is, like `is` does,
288
+ # so it doesn't turn into '%%' and match everything.
289
+ def contains_pattern(value)
290
+ return value if value.to_s.empty?
291
+
292
+ "%#{ActiveRecord::Base.sanitize_sql_like(value.to_s)}%"
293
+ end
294
+
295
+ # An attribute without a type may not be text in SQL (e.g. a count), cast
296
+ # it like search does. Typed columns are compared as they are, so an
297
+ # explicit `matches` on e.g. a boolean still fails (and the verifier
298
+ # reports it).
299
+ def text_col(col)
300
+ column.type.nil? ? "CAST(#{col} AS text)" : col
301
+ end
302
+
283
303
  # Unused at the moment
284
304
  def normalize(query)
285
305
  query
@@ -10,8 +10,9 @@ module Mensa
10
10
  return record_scope if query.blank?
11
11
  return record_scope unless record_scope.is_a?(ActiveRecord::Relation)
12
12
 
13
- # Aggregates (filter having) can't be in a WHERE
14
- searchable_attributes = columns.reject { |column| column.filter&.having? }.filter_map(&:attribute_for_condition).uniq
13
+ # Aggregates (filter having) can't be in a WHERE, and internal columns
14
+ # aren't shown, so a match on them can't be seen
15
+ searchable_attributes = columns.reject { |column| column.internal? || column.filter&.having? }.filter_map(&:attribute_for_condition).uniq
15
16
  return record_scope if searchable_attributes.empty?
16
17
 
17
18
  @search_order_clause = nil
data/lib/mensa/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mensa
2
- VERSION = "0.7.2"
2
+ VERSION = "0.7.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mensa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom de Grunt