ransack 6.1.1 → 6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a5e5f9de722c32e837eb4a964cb1eac3a122cd2bfaf11cadd9b6234ac08249c7
4
- data.tar.gz: 7322a874d888c2b98229f29fc23e4e1339d6c851f046b787312feedef1b30af2
3
+ metadata.gz: 759992ad53cbcdbb68e684fed6d2545aafba511e0cd0fe6092a47e2f8351b3e5
4
+ data.tar.gz: 5a112c165a263fc7dbc8f9521c47305d20cb4546ab2ed9409dc8da6dbcbdeeb0
5
5
  SHA512:
6
- metadata.gz: cb55b6504e333b50b125288e2ef1c86d5cfdfd571a1d913dab8af18574cf76ca4265d958bea2f86c5bc9534a93707dd84e08c43cd50c7c7d28b5d6381b6cee88
7
- data.tar.gz: c482f3ded58599621b46fa78d6c83ac06f9c5eccf0346243b52f8335ccc5222446716d1996444918c77ec0bfc85b95a67766a259fc5aa9637739b5ae86a71454
6
+ metadata.gz: 005dff71f14e277a4ebf5c45498e9ad308a5a6b6bb0c4b148a005e3fd0e0d2b3eeee75ecf3b7b40fe235b548defaeb869a9f3b02a4f2093e1612f9f65e70b6a9
7
+ data.tar.gz: 765bcae87720da3a104f5acdfbb25f28713865222a064dacc3eed27834f0d9d347a20ea5625fd024023173dc3ef51dd20c0eddc605855a1d3d364cacf3684f83
data/README.md CHANGED
@@ -35,6 +35,16 @@ gem 'ransack'
35
35
  [upgrading](https://activerecord-hackery.github.io/ransack/getting-started/upgrading/)
36
36
  and more. The site is built from the Markdown under [`docs/`](docs/).
37
37
 
38
+ ## We love ❤️ these projects
39
+
40
+ * [ActiveAdmin](https://github.com/activeadmin/activeadmin), the Rails admin framework whose filters are built on Ransack
41
+ * [Avo](https://github.com/avo-hq/avo), admin panels and internal tools for Rails, with search powered by Ransack
42
+ * [Spree](https://github.com/spree/spree), the open source commerce platform, which uses Ransack for its search and filtering
43
+ * [Solidus](https://github.com/solidusio/solidus), the open source eCommerce framework, which uses Ransack for its search and filtering
44
+ * [mobility-ransack](https://github.com/shioyama/mobility-ransack), which searches attributes translated with [Mobility](https://github.com/shioyama/mobility)
45
+ * [ransack_memory](https://github.com/richardrails/ransack_memory), which saves and restores Ransack's search params in the session
46
+ * [Ransack demo](https://github.com/activerecord-hackery/ransack_demo), an app showing advanced search forms built with Ransack
47
+
38
48
  ## Getting help and contributing
39
49
 
40
50
  * Questions belong in [GitHub Discussions](https://github.com/activerecord-hackery/ransack/discussions).
@@ -34,6 +34,15 @@ module Ransack
34
34
  attr.klass.type_for_attribute(name).type
35
35
  end
36
36
 
37
+ # The collation of the column behind this attribute, as the schema
38
+ # reports it, or nil when there is none: a ransacker, a column the
39
+ # adapter reports no collation for, or a non-string column.
40
+ def collation_for(attr)
41
+ return nil unless attr && attr.valid? && !attr.ransacker
42
+ column = attr.klass.columns_hash[attr.arel_attribute.name.to_s]
43
+ column.collation if column.respond_to?(:collation)
44
+ end
45
+
37
46
  # Evaluating a search leaves the context as it was, so the search can
38
47
  # be evaluated again, or given another condition or sort, and still
39
48
  # line up with the query Active Record builds (#1745, #1750).
@@ -57,6 +57,23 @@ module Ransack
57
57
  postgresql?
58
58
  end
59
59
 
60
+ # Whether LIKE against a column with this collation already ignores
61
+ # case, so a case-insensitive predicate need not lower the column.
62
+ #
63
+ # MySQL and MariaDB compare with the column's collation, and the
64
+ # default ones (utf8mb4_0900_ai_ci, utf8mb4_general_ci and the like)
65
+ # are case-insensitive: their names end in `_ci`. Lowering such a
66
+ # column changes no result, and it keeps a prefix LIKE from using the
67
+ # column's index, so a search on `i_start` scans the whole table.
68
+ # A `_bin` or `_cs` column, or one with no collation at all, is still
69
+ # lowered, since there LIKE is case-sensitive.
70
+ #
71
+ # Elsewhere the collation is not consulted: PostgreSQL has ILIKE, and
72
+ # SQLite's LIKE ignores the column's collation.
73
+ def case_insensitive_collation?(collation)
74
+ mysql? && collation.to_s.end_with?('_ci'.freeze)
75
+ end
76
+
60
77
  # CHAR_LENGTH is the SQL standard spelling and what PostgreSQL and MySQL
61
78
  # use; their LENGTH counts bytes on MySQL. SQLite has no CHAR_LENGTH,
62
79
  # and neither does Oracle, while both count characters with LENGTH, so
@@ -401,19 +401,29 @@ module Ransack
401
401
  end
402
402
 
403
403
  # The column (or ransacker expression) a predicate compares against.
404
- # A case-insensitive predicate lowers it, unless the dialect has a
405
- # case-insensitive LIKE of its own (ILIKE), in which case the lowering
406
- # is left to the database. LOWER() is applied as a function rather than
407
- # through Arel's Attribute#lower so that a ransacker returning any Arel
408
- # node — a SQL literal, an infix operation — is lowered too (#1357).
404
+ # A case-insensitive predicate lowers it, unless the database already
405
+ # matches it case-insensitively: the dialect has a case-insensitive
406
+ # LIKE of its own (ILIKE), or the column's collation ignores case (a
407
+ # `_ci` collation on MySQL). Leaving such a column bare keeps a prefix
408
+ # LIKE able to use its index. LOWER() is applied as a function rather
409
+ # than through Arel's Attribute#lower so that a ransacker returning any
410
+ # Arel node — a SQL literal, an infix operation — is lowered too (#1357).
409
411
  def attr_value_for_attribute(attr)
410
- if predicate.case_insensitive && !context.dialect.case_insensitive_like?
412
+ if predicate.case_insensitive && !case_insensitive_like_for?(attr)
411
413
  Arel::Nodes::NamedFunction.new('LOWER'.freeze, [attr.attr])
412
414
  else
413
415
  attr.attr
414
416
  end
415
417
  end
416
418
 
419
+ def case_insensitive_like_for?(attr)
420
+ dialect = context.dialect
421
+ return true if dialect.case_insensitive_like?
422
+
423
+ context.respond_to?(:collation_for) &&
424
+ dialect.case_insensitive_collation?(context.collation_for(attr))
425
+ end
426
+
417
427
  def default_type
418
428
  attribute = attributes.first
419
429
  predicate.type || (attribute && value_type_for_attribute(attribute))
@@ -1,3 +1,3 @@
1
1
  module Ransack
2
- VERSION = '6.1.1'
2
+ VERSION = '6.1.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ransack
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.1.1
4
+ version: 6.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Carroll