ransack 6.1.0 → 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 +12 -3
- data/lib/ransack/active_record/context.rb +9 -0
- data/lib/ransack/active_record/dialect.rb +17 -0
- data/lib/ransack/nodes/condition.rb +19 -9
- data/lib/ransack/nodes/grouping.rb +1 -1
- data/lib/ransack/nodes/node.rb +15 -12
- data/lib/ransack/nodes/sort.rb +1 -1
- data/lib/ransack/version.rb +1 -1
- metadata +2 -8
- data/lib/ransack/invalid_search_error.rb +0 -3
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
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
Ransack adds **searching and sorting to your Rails application** with plain Ruby
|
|
9
9
|
and ERB, without a search server or any other infrastructure.
|
|
10
10
|
|
|
11
|
-
Ransack is supported for Rails 8.1 on Ruby 3.
|
|
11
|
+
Ransack is supported for Rails 8.1 on Ruby 3.3 and later, on Postgres, MySQL, Trilogy and SQLite.
|
|
12
12
|
|
|
13
13
|
```ruby
|
|
14
14
|
gem 'ransack'
|
|
@@ -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).
|
|
@@ -53,8 +63,7 @@ for commercial support.
|
|
|
53
63
|
## Contributors
|
|
54
64
|
|
|
55
65
|
Ransack is maintained by [Sean Carroll](https://github.com/scarroll32),
|
|
56
|
-
[Deivid Rodriguez](https://github.com/deivid-rodriguez)
|
|
57
|
-
[Greg Molnar](https://github.com/gregmolnar) and
|
|
66
|
+
[Deivid Rodriguez](https://github.com/deivid-rodriguez) and
|
|
58
67
|
[a great group of contributors](https://github.com/activerecord-hackery/ransack/graphs/contributors).
|
|
59
68
|
It was created by [Ernie Miller](http://twitter.com/erniemiller). See
|
|
60
69
|
[Community and support](https://activerecord-hackery.github.io/ransack/project/community/)
|
|
@@ -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
|
|
@@ -136,7 +136,7 @@ module Ransack
|
|
|
136
136
|
end
|
|
137
137
|
when Hash
|
|
138
138
|
args.each do |index, attrs|
|
|
139
|
-
attrs = indifferent_params(attrs, 'attribute')
|
|
139
|
+
attrs = indifferent_params(attrs, 'an attribute')
|
|
140
140
|
build_attributes(attrs[:name], attrs[:ransacker_args])
|
|
141
141
|
end
|
|
142
142
|
else
|
|
@@ -162,7 +162,7 @@ module Ransack
|
|
|
162
162
|
end
|
|
163
163
|
when Hash
|
|
164
164
|
args.each do |index, attrs|
|
|
165
|
-
val = Value.new(@context, indifferent_params(attrs, 'value')[:value])
|
|
165
|
+
val = Value.new(@context, indifferent_params(attrs, 'a value')[:value])
|
|
166
166
|
self.values << val
|
|
167
167
|
end
|
|
168
168
|
else
|
|
@@ -274,7 +274,7 @@ module Ransack
|
|
|
274
274
|
}.freeze
|
|
275
275
|
|
|
276
276
|
def build(params)
|
|
277
|
-
indifferent_params(params, 'condition').each do |key, value|
|
|
277
|
+
indifferent_params(params, 'a condition').each do |key, value|
|
|
278
278
|
if key.match(/\A(a|v|p|m|attributes|values|predicate|predicate_name|combinator)\z/)
|
|
279
279
|
self.send("#{LONG_KEYS.fetch(key, key)}=", value)
|
|
280
280
|
end
|
|
@@ -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))
|
|
@@ -147,7 +147,7 @@ module Ransack
|
|
|
147
147
|
end
|
|
148
148
|
|
|
149
149
|
def build(params)
|
|
150
|
-
indifferent_params(params, 'grouping').each do |key, value|
|
|
150
|
+
indifferent_params(params, 'a grouping').each do |key, value|
|
|
151
151
|
case key
|
|
152
152
|
when /\A(g|c|m|groupings|conditions|combinator)\z/
|
|
153
153
|
self.send("#{key}=", value)
|
data/lib/ransack/nodes/node.rb
CHANGED
|
@@ -47,23 +47,26 @@ module Ransack
|
|
|
47
47
|
# Search params usually come from the request, so a grouping, condition
|
|
48
48
|
# or sort given as something other than a hash (`q[g]=x`) is a malformed
|
|
49
49
|
# search, not a programming error, whether or not the search is strict.
|
|
50
|
+
# Strong parameters are unwrapped as `Search#initialize` unwraps them, so
|
|
51
|
+
# `build_grouping(params[:g])` takes what `ransack(params[:q])` does. That
|
|
52
|
+
# does not make the search permitted: only `Search#initialize` reads it.
|
|
50
53
|
def indifferent_params(params, node_name)
|
|
54
|
+
params = params.to_unsafe_h if params.respond_to?(:to_unsafe_h)
|
|
51
55
|
return params.with_indifferent_access if params.respond_to?(:with_indifferent_access)
|
|
52
56
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
end
|
|
57
|
+
raise InvalidSearchError,
|
|
58
|
+
"Invalid argument (#{params.class}) supplied for #{node_name}"
|
|
59
|
+
end
|
|
56
60
|
|
|
57
|
-
# A name, predicate, direction or combinator is a single value. Given an
|
|
58
|
-
# array or a hash (`q[s][0][dir][]=desc`), it used to be stringified and
|
|
59
|
-
# then silently ignored or defaulted, so the search ran as something
|
|
60
|
-
# other than what was asked for.
|
|
61
|
-
def scalar_param(value, field)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
raise InvalidSearchError, "Invalid argument (#{value.class}) supplied for #{field}"
|
|
65
|
-
end
|
|
61
|
+
# A name, predicate, direction or combinator is a single value. Given an
|
|
62
|
+
# array or a hash (`q[s][0][dir][]=desc`), it used to be stringified and
|
|
63
|
+
# then silently ignored or defaulted, so the search ran as something
|
|
64
|
+
# other than what was asked for.
|
|
65
|
+
def scalar_param(value, field)
|
|
66
|
+
return value unless value.is_a?(Enumerable) || value.respond_to?(:to_unsafe_h)
|
|
66
67
|
|
|
68
|
+
raise InvalidSearchError, "Invalid argument (#{value.class}) supplied for #{field}"
|
|
69
|
+
end
|
|
67
70
|
end
|
|
68
71
|
end
|
|
69
72
|
end
|
data/lib/ransack/nodes/sort.rb
CHANGED
data/lib/ransack/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ransack
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 6.1.
|
|
4
|
+
version: 6.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
- Ernie Miller
|
|
8
|
-
- Ryan Bigg
|
|
9
|
-
- Jon Atack
|
|
10
7
|
- Sean Carroll
|
|
11
8
|
- David Rodríguez
|
|
9
|
+
- Ernie Miller
|
|
12
10
|
bindir: bin
|
|
13
11
|
cert_chain: []
|
|
14
12
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
@@ -59,9 +57,6 @@ description: Powerful object-based searching and filtering for Active Record wit
|
|
|
59
57
|
advanced features like complex boolean queries, association searching, custom predicates
|
|
60
58
|
and i18n support.
|
|
61
59
|
email:
|
|
62
|
-
- ernie@erniemiller.org
|
|
63
|
-
- radarlistener@gmail.com
|
|
64
|
-
- jonnyatack@gmail.com
|
|
65
60
|
- sean@immersive-app.com
|
|
66
61
|
executables: []
|
|
67
62
|
extensions: []
|
|
@@ -86,7 +81,6 @@ files:
|
|
|
86
81
|
- lib/ransack/helpers.rb
|
|
87
82
|
- lib/ransack/helpers/form_builder.rb
|
|
88
83
|
- lib/ransack/helpers/form_helper.rb
|
|
89
|
-
- lib/ransack/invalid_search_error.rb
|
|
90
84
|
- lib/ransack/locale/ar.yml
|
|
91
85
|
- lib/ransack/locale/az.yml
|
|
92
86
|
- lib/ransack/locale/bg.yml
|