ransack 2.4.2 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/cronjob.yml +6 -9
  3. data/.github/workflows/rubocop.yml +1 -1
  4. data/.github/workflows/test.yml +25 -34
  5. data/CHANGELOG.md +18 -1
  6. data/CONTRIBUTING.md +4 -3
  7. data/README.md +76 -10
  8. data/docs/release_process.md +2 -5
  9. data/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +20 -1
  10. data/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +0 -1
  11. data/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +11 -1
  12. data/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +0 -4
  13. data/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +0 -1
  14. data/lib/polyamorous/{activerecord_6.2_ruby_2 → activerecord_7.0_ruby_2}/join_association.rb +0 -0
  15. data/lib/polyamorous/{activerecord_6.2_ruby_2 → activerecord_7.0_ruby_2}/join_dependency.rb +0 -0
  16. data/lib/polyamorous/{activerecord_6.2_ruby_2 → activerecord_7.0_ruby_2}/reflection.rb +0 -0
  17. data/lib/polyamorous.rb +1 -0
  18. data/lib/ransack/adapters/active_record/base.rb +1 -1
  19. data/lib/ransack/adapters/active_record/context.rb +6 -2
  20. data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +10 -9
  21. data/lib/ransack/configuration.rb +16 -2
  22. data/lib/ransack/helpers/form_helper.rb +1 -1
  23. data/lib/ransack/locale/sv.yml +70 -0
  24. data/lib/ransack/nodes/sort.rb +2 -2
  25. data/lib/ransack/search.rb +2 -1
  26. data/lib/ransack/translate.rb +1 -1
  27. data/lib/ransack/version.rb +1 -1
  28. data/ransack.gemspec +2 -2
  29. data/spec/polyamorous/activerecord_compatibility_spec.rb +15 -0
  30. data/spec/polyamorous/join_association_spec.rb +1 -6
  31. data/spec/polyamorous/join_dependency_spec.rb +0 -16
  32. data/spec/ransack/adapters/active_record/base_spec.rb +18 -10
  33. data/spec/ransack/configuration_spec.rb +14 -0
  34. data/spec/ransack/helpers/form_helper_spec.rb +1 -2
  35. data/spec/ransack/nodes/condition_spec.rb +13 -0
  36. data/spec/ransack/search_spec.rb +117 -27
  37. data/spec/support/schema.rb +33 -0
  38. metadata +17 -16
  39. data/lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb +0 -24
  40. data/lib/polyamorous/activerecord_5.2_ruby_2/join_dependency.rb +0 -79
  41. data/lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7e53f2a86ba264e751c3311254c7cb4b25efdb0c876310835b6f6221ab24928
4
- data.tar.gz: 161ca5255a24fa42c63d6afbbf38e518581189db773e7e43940b31b1b8d86850
3
+ metadata.gz: 613abc9bb025f01243aa427878dec0cb7e990e3a9deb3e1436b7f0f3b124bf44
4
+ data.tar.gz: 1466899c236bc6c9d1e95fc5262b5b3d6cde18f51929273168ff3286ead4be34
5
5
  SHA512:
6
- metadata.gz: 17c4701dbf3523dfa16feae0dd0dddc8bd077237d7e695eb69664f1b9c5ab5e2fea4a59b5878fe8e607b135ea834f12284f03c42a9ce2971f2f9c9b65d347205
7
- data.tar.gz: 4c9d09980609ffc43bc505a947781b9fcdc97efb7897c3bbc3278d8391ab219e4fdffd8a813272a3af7403eefc162fddb6f9f379b713894d3951ff2fc7a141f3
6
+ metadata.gz: 2d8f6c96d9b0d4af4d5d64c3aa24cbe79abefe78388ff35637577a46b99b99decf25e51433368634ae557a72707470a9291c62ca33cae15b7ce0edb51b682712
7
+ data.tar.gz: 66bcf53be5d9f201f0e51db95140a56b29e3d61c0b9d79fbd3238e3e67a2b0bb5463dc08ebf445155d502f1b8bfb87b0be38040521219733a852471f32385e0b
@@ -11,9 +11,8 @@ jobs:
11
11
  fail-fast: false
12
12
  matrix:
13
13
  ruby:
14
- - 3.0.0
15
- - 2.7.2
16
- - 2.6.6
14
+ - 3.0.2
15
+ - 2.7.4
17
16
  env:
18
17
  DB: sqlite3
19
18
  RAILS: main
@@ -34,9 +33,8 @@ jobs:
34
33
  fail-fast: false
35
34
  matrix:
36
35
  ruby:
37
- - 3.0.0
38
- - 2.7.2
39
- - 2.6.6
36
+ - 3.0.2
37
+ - 2.7.4
40
38
  env:
41
39
  DB: mysql
42
40
  RAILS: main
@@ -66,9 +64,8 @@ jobs:
66
64
  fail-fast: false
67
65
  matrix:
68
66
  ruby:
69
- - 3.0.0
70
- - 2.7.2
71
- - 2.6.6
67
+ - 3.0.2
68
+ - 2.7.4
72
69
  env:
73
70
  DB: postgres
74
71
  RAILS: main
@@ -13,7 +13,7 @@ jobs:
13
13
  - name: Set up Ruby
14
14
  uses: ruby/setup-ruby@v1
15
15
  with:
16
- ruby-version: 3.0.0
16
+ ruby-version: 3.0.1
17
17
  - name: Install gems
18
18
  run: bundle install --jobs 4 --retry 3
19
19
  - name: Run RuboCop
@@ -11,20 +11,17 @@ jobs:
11
11
  fail-fast: false
12
12
  matrix:
13
13
  rails:
14
- - v6.1.1
15
- - v6.0.3
14
+ - v7.0.0
15
+ - v6.1.4
16
+ - v6.0.4
16
17
  - 6-0-stable
17
- - 5-2-stable
18
- - v5.2.4
19
18
  ruby:
20
- - 3.0.0
21
- - 2.7.2
22
- - 2.6.6
19
+ - 3.0.2
20
+ - 2.7.4
21
+ - 2.6.7
23
22
  exclude:
24
- - rails: v5.2.4
25
- ruby: 3.0.0
26
- - rails: 5-2-stable
27
- ruby: 3.0.0
23
+ - rails: v7.0.0
24
+ ruby: 2.6.7
28
25
  env:
29
26
  DB: sqlite3
30
27
  RAILS: ${{ matrix.rails }}
@@ -45,20 +42,17 @@ jobs:
45
42
  fail-fast: false
46
43
  matrix:
47
44
  rails:
48
- - v6.1.1
49
- - v6.0.3
45
+ - v7.0.0
46
+ - v6.1.4
47
+ - v6.0.4
50
48
  - 6-0-stable
51
- - 5-2-stable
52
- - v5.2.4
53
49
  ruby:
54
- - 3.0.0
55
- - 2.7.2
56
- - 2.6.6
50
+ - 3.0.2
51
+ - 2.7.4
52
+ - 2.6.7
57
53
  exclude:
58
- - rails: v5.2.4
59
- ruby: 3.0.0
60
- - rails: 5-2-stable
61
- ruby: 3.0.0
54
+ - rails: v7.0.0
55
+ ruby: 2.6.7
62
56
  env:
63
57
  DB: mysql
64
58
  RAILS: ${{ matrix.rails }}
@@ -88,20 +82,17 @@ jobs:
88
82
  fail-fast: false
89
83
  matrix:
90
84
  rails:
91
- - v6.1.1
92
- - v6.0.3
85
+ - v7.0.0
86
+ - v6.1.4
87
+ - v6.0.4
93
88
  - 6-0-stable
94
- - 5-2-stable
95
- - v5.2.4
96
89
  ruby:
97
- - 3.0.0
98
- - 2.7.2
99
- - 2.6.6
90
+ - 3.0.2
91
+ - 2.7.4
92
+ - 2.6.7
100
93
  exclude:
101
- - rails: v5.2.4
102
- ruby: 3.0.0
103
- - rails: 5-2-stable
104
- ruby: 3.0.0
94
+ - rails: v7.0.0
95
+ ruby: 2.6.7
105
96
  env:
106
97
  DB: postgres
107
98
  RAILS: ${{ matrix.rails }}
@@ -144,7 +135,7 @@ jobs:
144
135
  - name: Set up Ruby
145
136
  uses: ruby/setup-ruby@v1
146
137
  with:
147
- ruby-version: 3.0.0
138
+ ruby-version: 3.0.2
148
139
  - name: Install dependencies
149
140
  run: bundle install
150
141
  - name: Run bug report templates
data/CHANGELOG.md CHANGED
@@ -1,7 +1,24 @@
1
1
  # Change Log
2
2
 
3
+ ## Unreleased
4
+
5
+ ## 2.6.0 - 2022-03-08
6
+
7
+ * Fix regression when joining a table with itself.
8
+ PR [1275](https://github.com/activerecord-hackery/ransack/pull/1276)
9
+
10
+ * Drop support for ActiveRecord older than 6.0.4.
11
+ PR [1276](https://github.com/activerecord-hackery/ransack/pull/1276)
12
+
13
+ ## 2.5.0 - 2021-12-26
14
+
15
+ * ActiveRecord 7.0 support
16
+
3
17
  * Drop support for rubies under 2.5. PR #1189
4
18
 
19
+ * Have casted array predicates type checked to Arel::Nodes::Casted fixing non-casted array predicates.
20
+ PR [1246](https://github.com/activerecord-hackery/ransack/pull/1246)
21
+
5
22
  ## 2.4.1 - 2020-12-21
6
23
 
7
24
  * Add `ActiveRecord::Base.ransack!` which raises error if passed unknown condition
@@ -200,7 +217,7 @@
200
217
  ignored when block parameter is specified.
201
218
  PR [#818](https://github.com/activerecord-hackery/ransack/pull/818).
202
219
 
203
- * No need pass some arugments to JoinAssociation#join_constraints in Rails 5.1.
220
+ * No need pass some arguments to JoinAssociation#join_constraints in Rails 5.1.
204
221
  PR [#814](https://github.com/activerecord-hackery/ransack/pull/814).
205
222
  Fixes [#807](https://github.com/activerecord-hackery/ransack/issues/807).
206
223
  Reference [rails/rails#28267](https://github.com/rails/rails/pull/28267)
data/CONTRIBUTING.md CHANGED
@@ -64,9 +64,7 @@ Here's a quick guide:
64
64
  2. Create a thoughtfully-named branch for your changes (`git checkout -b my-new-feature`).
65
65
 
66
66
  3. Install the development dependencies by running `bundle install`.
67
- To install rails other than latest (set in Gemfile): `RAILS='5-2-stable' bundle install`
68
-
69
- $ RAILS='5-2-stable' bundle install
67
+ To install rails other than latest (set in Gemfile): `RAILS='6-0-stable' bundle install`
70
68
 
71
69
  4. Begin by running the tests. We only take pull requests with passing tests,
72
70
  and it's great to know that you have a clean slate:
@@ -115,6 +113,9 @@ Here's a quick guide:
115
113
  $ git config --global user.email "contributor@example.com"
116
114
 
117
115
  10. Commit your changes (`git commit -am 'Add feature/fix bug/improve docs'`).
116
+ If your pull request only contains documentation changes, please remember
117
+ to add `[skip ci]` to the beginning of your commit message so the CI
118
+ test suite doesn't :runner: needlessly.
118
119
 
119
120
  11. If necessary, rebase your commits into logical chunks, without errors. To
120
121
  interactively rebase and cherry-pick from, say, the last 10 commits:
data/README.md CHANGED
@@ -11,13 +11,11 @@ Ransack enables the creation of both
11
11
  for your Ruby on Rails application
12
12
  ([demo source code here](https://github.com/activerecord-hackery/ransack_demo)).
13
13
  If you're looking for something that simplifies query generation at the model
14
- or controller layer, you're probably not looking for Ransack (or MetaSearch,
15
- for that matter). Try [Squeel](https://github.com/activerecord-hackery/squeel)
16
- instead.
14
+ or controller layer, you're probably not looking for Ransack.
17
15
 
18
16
  ## Getting started
19
17
 
20
- Ransack is supported for Rails 6.1, 6.0, 5.2 on Ruby 2.6.6 and later.
18
+ Ransack is supported for Rails 7.0, 6.x on Ruby 2.6.6 and later.
21
19
 
22
20
  In your Gemfile, for the last officially released gem:
23
21
 
@@ -65,19 +63,18 @@ this example, with preloading each Person's Articles and pagination):
65
63
  def index
66
64
  @q = Person.ransack(params[:q])
67
65
  @people = @q.result.includes(:articles).page(params[:page])
68
-
69
- # or use `to_a.uniq` to remove duplicates (can also be done in the view):
70
- @people = @q.result.includes(:articles).page(params[:page]).to_a.uniq
71
66
  end
72
67
  ```
73
68
 
74
- ##### Default search parameter
69
+ ##### Default search options
70
+
71
+ **Search parameter**
75
72
 
76
73
  Ransack uses a default `:q` param key for search params. This may be changed by
77
74
  setting the `search_key` option in a Ransack initializer file (typically
78
75
  `config/initializers/ransack.rb`):
79
76
 
80
- ```
77
+ ```ruby
81
78
  Ransack.configure do |c|
82
79
  # Change default search parameter key name.
83
80
  # Default key name is :q
@@ -85,6 +82,19 @@ Ransack.configure do |c|
85
82
  end
86
83
  ```
87
84
 
85
+ **String search**
86
+
87
+ After version 2.4.0 when searching a string query Ransack by default strips all whitespace around the query string.
88
+ This may be disabled by setting the `strip_whitespace` option in a Ransack initializer file:
89
+
90
+ ```ruby
91
+ Ransack.configure do |c|
92
+ # Change whitespace stripping behaviour.
93
+ # Default is true
94
+ c.strip_whitespace = false
95
+ end
96
+ ```
97
+
88
98
  #### In your view
89
99
 
90
100
  The two primary Ransack view helpers are `search_form_for` and `sort_link`,
@@ -263,8 +273,45 @@ Ransack.configure do |c|
263
273
  end
264
274
  ```
265
275
 
276
+ To treat nulls as having the lowest or highest value respectively. To force nulls to always be first or last, use
277
+
278
+ ```rb
279
+ Ransack.configure do |c|
280
+ c.postgres_fields_sort_option = :nulls_always_first # or :nulls_always_last
281
+ end
282
+ ```
283
+
266
284
  See this feature: https://www.postgresql.org/docs/13/queries-order.html
267
285
 
286
+ #### Case Insensitive Sorting in PostgreSQL
287
+
288
+ In order to request PostgreSQL to do a case insensitive sort for all string columns of a model at once, Ransack can be extended by using this approach:
289
+
290
+ ```ruby
291
+ module RansackObject
292
+
293
+ def self.included(base)
294
+ base.columns.each do |column|
295
+ if column.type == :string
296
+ base.ransacker column.name.to_sym, type: :string do
297
+ Arel.sql("lower(#{base.table_name}.#{column.name})")
298
+ end
299
+ end
300
+ end
301
+ end
302
+ end
303
+ ```
304
+
305
+ ```ruby
306
+ class UserWithManyAttributes < ActiveRecord::Base
307
+ include RansackObject
308
+ end
309
+ ```
310
+
311
+ If this approach is taken, it is advisable to [add a functional index](https://www.postgresql.org/docs/13/citext.html).
312
+
313
+ This was originally asked in [a Ransack issue](https://github.com/activerecord-hackery/ransack/issues/1201) and a solution was found on [Stack Overflow](https://stackoverflow.com/a/34677378).
314
+
268
315
  ### Advanced Mode
269
316
 
270
317
  "Advanced" searches (ab)use Rails' nested attributes functionality in order to
@@ -423,6 +470,25 @@ query parameters in your URLs.
423
470
  <% end %>
424
471
  ```
425
472
 
473
+ You can also use `ransack_alias` for sorting.
474
+
475
+ ```ruby
476
+ class Post < ActiveRecord::Base
477
+ belongs_to :author
478
+
479
+ # Abbreviate :author_first_name to :author
480
+ ransack_alias :author, :author_first_name
481
+ end
482
+ ```
483
+
484
+ Now, you can use `:author` instead of `:author_first_name` in a `sort_link`.
485
+
486
+ ```erb
487
+ <%= sort_link(@q, :author) %>
488
+ ```
489
+
490
+ Note that using `:author_first_name_or_author_last_name_cont` would produce an invalid sql query. In those cases, Ransack ignores the sorting clause.
491
+
426
492
  ### Search Matchers
427
493
 
428
494
  List of all possible predicates
@@ -719,7 +785,7 @@ Article.ransack!(unknown_attr_eq: 'Ernie')
719
785
  # ArgumentError: Invalid search term unknown_attr_eq
720
786
  ```
721
787
 
722
- This is equivilent to the `ignore_unknown_conditions` configuration option,
788
+ This is equivalent to the `ignore_unknown_conditions` configuration option,
723
789
  except it may be applied on a case-by-case basis.
724
790
 
725
791
  ### Using Scopes/Class Methods
@@ -5,12 +5,9 @@
5
5
  To release a new version of Ransack and publish it to RubyGems, take the following steps:
6
6
 
7
7
  - Create a new release, marked `Prerelease`.
8
- <<<<<<< Updated upstream
9
8
  - Update the versions file to the new release, commit and push to `master`.
10
- =======
11
- - Update the [version.rb](../lib/ransack/version.rb) file to the new release, commit and push to `master`.
12
- >>>>>>> Stashed changes
13
- - From the terminal, run the following commands
9
+ - Update the [`version.rb`](../lib/ransack/version.rb) file to the new release, commit and push to `master`.
10
+ - From the terminal, run the following commands:
14
11
 
15
12
  ```bash
16
13
  rake build
@@ -1 +1,20 @@
1
- require 'polyamorous/activerecord_5.2_ruby_2/join_association'
1
+ module Polyamorous
2
+ module JoinAssociationExtensions
3
+ include SwappingReflectionClass
4
+ def self.prepended(base)
5
+ base.class_eval { attr_reader :join_type }
6
+ end
7
+
8
+ def initialize(reflection, children, polymorphic_class = nil, join_type = Arel::Nodes::InnerJoin)
9
+ @join_type = join_type
10
+ if polymorphic_class && ::ActiveRecord::Base > polymorphic_class
11
+ swapping_reflection_klass(reflection, polymorphic_class) do |reflection|
12
+ super(reflection, children)
13
+ self.reflection.options[:polymorphic] = true
14
+ end
15
+ else
16
+ super(reflection, children)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,4 +1,3 @@
1
- # active_record_6.0_ruby_2/join_dependency.rb
2
1
  module Polyamorous
3
2
  module JoinDependencyExtensions
4
3
  # Replaces ActiveRecord::Associations::JoinDependency#build
@@ -1 +1,11 @@
1
- require 'polyamorous/activerecord_5.2_ruby_2/reflection'
1
+ module Polyamorous
2
+ module ReflectionExtensions
3
+ def join_scope(table, foreign_table, foreign_klass)
4
+ if respond_to?(:polymorphic?) && polymorphic?
5
+ super.where!(foreign_table[foreign_type].eq(klass.name))
6
+ else
7
+ super
8
+ end
9
+ end
10
+ end
11
+ end
@@ -66,9 +66,5 @@ module Polyamorous
66
66
 
67
67
  joins
68
68
  end
69
-
70
- def ==(other)
71
- base_klass == other.base_klass
72
- end
73
69
  end
74
70
  end
@@ -1,4 +1,3 @@
1
- # active_record_6.1_ruby_2/join_dependency.rb
2
1
  module Polyamorous
3
2
  module JoinDependencyExtensions
4
3
  # Replaces ActiveRecord::Associations::JoinDependency#build
@@ -0,0 +1 @@
1
+ require 'polyamorous/polyamorous'
@@ -70,7 +70,7 @@ module Ransack
70
70
  end
71
71
 
72
72
  # ransack_scope_skip_sanitize_args, by default, returns an empty array.
73
- # i.e. use the sanitize_scope_args setting to determin if args should be converted.
73
+ # i.e. use the sanitize_scope_args setting to determine if args should be converted.
74
74
  # For overriding with a list of scopes which should be passed the args as-is.
75
75
  #
76
76
  def ransackable_scopes_skip_sanitize_args
@@ -44,9 +44,13 @@ module Ransack
44
44
  else
45
45
  case Ransack.options[:postgres_fields_sort_option]
46
46
  when :nulls_first
47
- scope_or_sort = scope_or_sort.direction == :asc ? "#{scope_or_sort.to_sql} NULLS FIRST" : "#{scope_or_sort.to_sql} NULLS LAST"
47
+ scope_or_sort = scope_or_sort.direction == :asc ? Arel.sql("#{scope_or_sort.to_sql} NULLS FIRST") : Arel.sql("#{scope_or_sort.to_sql} NULLS LAST")
48
48
  when :nulls_last
49
- scope_or_sort = scope_or_sort.direction == :asc ? "#{scope_or_sort.to_sql} NULLS LAST" : "#{scope_or_sort.to_sql} NULLS FIRST"
49
+ scope_or_sort = scope_or_sort.direction == :asc ? Arel.sql("#{scope_or_sort.to_sql} NULLS LAST") : Arel.sql("#{scope_or_sort.to_sql} NULLS FIRST")
50
+ when :nulls_always_first
51
+ scope_or_sort = Arel.sql("#{scope_or_sort.to_sql} NULLS FIRST")
52
+ when :nulls_always_last
53
+ scope_or_sort = Arel.sql("#{scope_or_sort.to_sql} NULLS LAST")
50
54
  end
51
55
 
52
56
  relation = relation.order(scope_or_sort)
@@ -47,18 +47,19 @@ module Ransack
47
47
  end
48
48
 
49
49
  def casted_array?(predicate)
50
- (predicate.respond_to?(:value) && predicate.value.is_a?(Array)) || # Rails 6.1
51
- (predicate.respond_to?(:val) && predicate.val.is_a?(Array)) # Rails 5.2, 6.0
50
+ value_from(predicate).is_a?(Array) && predicate.is_a?(Arel::Nodes::Casted)
52
51
  end
53
52
 
54
- def format_values_for(predicate)
55
- value = if predicate.respond_to?(:value)
56
- predicate.value # Rails 6.1
57
- else
58
- predicate.val # Rails 5.2, 6.0
59
- end
53
+ def value_from(predicate)
54
+ if predicate.respond_to?(:value)
55
+ predicate.value # Rails 6.1
56
+ elsif predicate.respond_to?(:val)
57
+ predicate.val # Rails 6.0
58
+ end
59
+ end
60
60
 
61
- value.map do |val|
61
+ def format_values_for(predicate)
62
+ value_from(predicate).map do |val|
62
63
  val.is_a?(String) ? Arel::Nodes.build_quoted(val) : val
63
64
  end
64
65
  end
@@ -34,7 +34,8 @@ module Ransack
34
34
  :down_arrow => '&#9650;'.freeze,
35
35
  :default_arrow => nil,
36
36
  :sanitize_scope_args => true,
37
- :postgres_fields_sort_option => nil
37
+ :postgres_fields_sort_option => nil,
38
+ :strip_whitespace => true
38
39
  }
39
40
 
40
41
  def configure
@@ -148,7 +149,7 @@ module Ransack
148
149
  # User may want to configure it like this:
149
150
  #
150
151
  # Ransack.configure do |c|
151
- # c.postgres_fields_sort_option = :nulls_first # or :nulls_last
152
+ # c.postgres_fields_sort_option = :nulls_first # or e.g. :nulls_always_last
152
153
  # end
153
154
  #
154
155
  # See this feature: https://www.postgresql.org/docs/13/queries-order.html
@@ -170,6 +171,19 @@ module Ransack
170
171
  self.options[:hide_sort_order_indicators] = boolean
171
172
  end
172
173
 
174
+ # By default, Ransack displays strips all whitespace when searching for a string.
175
+ # The default may be globally changed in an initializer file like
176
+ # `config/initializers/ransack.rb` as follows:
177
+ #
178
+ # Ransack.configure do |config|
179
+ # # Enable whitespace stripping for string searches
180
+ # config.strip_whitespace = true
181
+ # end
182
+ #
183
+ def strip_whitespace=(boolean)
184
+ self.options[:strip_whitespace] = boolean
185
+ end
186
+
173
187
  def arel_predicate_with_suffix(arel_predicate, suffix)
174
188
  if arel_predicate === Proc
175
189
  proc { |v| "#{arel_predicate.call(v)}#{suffix}" }
@@ -145,7 +145,7 @@ module Ransack
145
145
  private
146
146
 
147
147
  def parameters_hash(params)
148
- if ::ActiveRecord::VERSION::MAJOR >= 5 && params.respond_to?(:to_unsafe_h)
148
+ if params.respond_to?(:to_unsafe_h)
149
149
  params.to_unsafe_h
150
150
  else
151
151
  params
@@ -0,0 +1,70 @@
1
+ sv:
2
+ ransack:
3
+ search: "sök"
4
+ predicate: "predikat"
5
+ and: "och"
6
+ or: "eller"
7
+ any: "vilken som"
8
+ all: "alla"
9
+ combinator: "kombinator"
10
+ attribute: "attribut"
11
+ value: "värde"
12
+ condition: "villkor"
13
+ sort: "sortera"
14
+ asc: "stigande"
15
+ desc: "fallande"
16
+ predicates:
17
+ eq: "lika med"
18
+ eq_any: "lika med vilket som"
19
+ eq_all: "lika med alla"
20
+ not_eq: "inte lika med"
21
+ not_eq_any: "inte lika med någon"
22
+ not_eq_all: "inte lika med alla"
23
+ matches: "matchar"
24
+ matches_any: "matchar någon"
25
+ matches_all: "matchar alla"
26
+ does_not_match: "matchar inte"
27
+ does_not_match_any: "matchar inte någon"
28
+ does_not_match_all: "matchar inte alla"
29
+ lt: "mindre än"
30
+ lt_any: "mindre än någon"
31
+ lt_all: "mindre än alla"
32
+ lteq: "mindre än eller lika med"
33
+ lteq_any: "mindre än eller lika med någon"
34
+ lteq_all: "mindre än eller lika med alla"
35
+ gt: "större än"
36
+ gt_any: "större än någon"
37
+ gt_all: "större än alla"
38
+ gteq: "större än eller lika med"
39
+ gteq_any: "större än eller lika med någon"
40
+ gteq_all: "större än eller lika med alla"
41
+ in: "i"
42
+ in_any: "i någon"
43
+ in_all: "i alla"
44
+ not_in: "inte i"
45
+ not_in_any: "inte i någon"
46
+ not_in_all: "inte i alla"
47
+ cont: "innehåller"
48
+ cont_any: "innehåller någon"
49
+ cont_all: "innehåller alla"
50
+ not_cont: "innehåller inte"
51
+ not_cont_any: "innehåller inte någon"
52
+ not_cont_all: "innehåller inte alla"
53
+ start: "börjar med"
54
+ start_any: "börjar med någon"
55
+ start_all: "börjar med alla"
56
+ not_start: "börjar inte med"
57
+ not_start_any: "börjar inte med någon"
58
+ not_start_all: "börjar inte med alla"
59
+ end: "slutar med"
60
+ end_any: "slutar med någon"
61
+ end_all: "slutar med alla"
62
+ not_end: "slutar inte med"
63
+ not_end_any: "slutar inte med någon"
64
+ not_end_all: "slutar inte med alla"
65
+ 'true': "är sant"
66
+ 'false': "är falskt"
67
+ present: "existerar"
68
+ blank: "är tom"
69
+ 'null': "är null"
70
+ not_null: "är inte null"
@@ -31,8 +31,8 @@ module Ransack
31
31
  end
32
32
 
33
33
  def name=(name)
34
- @name = name
35
- context.bind(self, name)
34
+ @name = context.ransackable_alias(name) || name
35
+ context.bind(self, @name)
36
36
  end
37
37
 
38
38
  def dir=(dir)
@@ -15,10 +15,11 @@ module Ransack
15
15
  :translate, :to => :base
16
16
 
17
17
  def initialize(object, params = {}, options = {})
18
+ strip_whitespace = options.fetch(:strip_whitespace, Ransack.options[:strip_whitespace])
18
19
  params = params.to_unsafe_h if params.respond_to?(:to_unsafe_h)
19
20
  if params.is_a? Hash
20
21
  params = params.dup
21
- params = params.transform_values { |v| v.is_a?(String) ? v.strip : v }
22
+ params = params.transform_values { |v| v.is_a?(String) && strip_whitespace ? v.strip : v }
22
23
  params.delete_if { |k, v| [*v].all?{ |i| i.blank? && i != false } }
23
24
  else
24
25
  params = {}
@@ -32,6 +32,7 @@ module Ransack
32
32
  defaults = base_ancestors.map do |klass|
33
33
  "ransack.attributes.#{i18n_key(klass)}.#{original_name}".to_sym
34
34
  end
35
+ defaults << options.delete(:default) if options[:default]
35
36
 
36
37
  translated_names = attribute_names.map do |name|
37
38
  attribute_name(context, name, options[:include_associations])
@@ -48,7 +49,6 @@ module Ransack
48
49
  defaults << "%{attributes}".freeze
49
50
  end
50
51
 
51
- defaults << options.delete(:default) if options[:default]
52
52
  options.reverse_merge! count: 1, default: defaults
53
53
  I18n.translate(defaults.shift, **options.merge(interpolations))
54
54
  end
@@ -1,3 +1,3 @@
1
1
  module Ransack
2
- VERSION = '2.4.2'
2
+ VERSION = '2.6.0'
3
3
  end