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 +4 -4
- data/README.md +10 -0
- data/lib/ransack/active_record/context.rb +9 -0
- data/lib/ransack/active_record/dialect.rb +17 -0
- data/lib/ransack/nodes/condition.rb +16 -6
- data/lib/ransack/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: 759992ad53cbcdbb68e684fed6d2545aafba511e0cd0fe6092a47e2f8351b3e5
|
|
4
|
+
data.tar.gz: 5a112c165a263fc7dbc8f9521c47305d20cb4546ab2ed9409dc8da6dbcbdeeb0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
405
|
-
# case-
|
|
406
|
-
#
|
|
407
|
-
#
|
|
408
|
-
#
|
|
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 && !
|
|
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))
|
data/lib/ransack/version.rb
CHANGED