ransack 3.1.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +0 -3
- data/CHANGELOG.md +8 -0
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +2 -2
- data/docs/yarn.lock +3 -3
- data/lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb +11 -1
- data/lib/ransack/adapters/active_record/context.rb +17 -49
- data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +2 -10
- data/lib/ransack/constants.rb +0 -3
- data/lib/ransack/helpers/form_helper.rb +1 -1
- data/lib/ransack/version.rb +1 -1
- data/ransack.gemspec +2 -2
- data/spec/helpers/polyamorous_helper.rb +2 -8
- data/spec/ransack/helpers/form_helper_spec.rb +12 -0
- metadata +7 -10
- data/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +0 -20
- data/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +0 -79
- data/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f37dfefd63333903d6b36084a8dda1193ca31788777b2645d25b96dd97d2d2c
|
4
|
+
data.tar.gz: dba86f7268c931801e1caf32f3552ebfeecc06fec2f773130118cc2c809c61e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c8364c70e6536c5aa5dca37c5539164d89dab6fb9e582501dbf5611ff4a647aa0b5ff69450a0b4d480de4d61e62708b3c376ffb6813c0f06ff6b0a591c670f6
|
7
|
+
data.tar.gz: 4681b4c7f4e03002b968e165abf930a6b42dfc1e4d740a0bb8a034a9c805b1f956d6f82ab5ca0e39117a8a08b8899b849e34ccf665ac5f7c36fd1aec83ebe3e5
|
data/.github/workflows/test.yml
CHANGED
@@ -13,7 +13,6 @@ jobs:
|
|
13
13
|
rails:
|
14
14
|
- v7.0.2
|
15
15
|
- v6.1.5
|
16
|
-
- v6.0.4
|
17
16
|
ruby:
|
18
17
|
- 3.1.1
|
19
18
|
- 3.0.2
|
@@ -40,7 +39,6 @@ jobs:
|
|
40
39
|
rails:
|
41
40
|
- v7.0.2
|
42
41
|
- v6.1.5
|
43
|
-
- v6.0.4
|
44
42
|
ruby:
|
45
43
|
- 3.1.1
|
46
44
|
- 3.0.2
|
@@ -76,7 +74,6 @@ jobs:
|
|
76
74
|
rails:
|
77
75
|
- v7.0.2
|
78
76
|
- v6.1.5
|
79
|
-
- v6.0.4
|
80
77
|
ruby:
|
81
78
|
- 3.1.1
|
82
79
|
- 3.0.2
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
+
## 3.2.0 - 2022-05-08
|
6
|
+
|
7
|
+
* Drop Rails 6.0 support.
|
8
|
+
PR [1318](https://github.com/activerecord-hackery/ransack/pull/1318)
|
9
|
+
|
10
|
+
* Exclude "host" from params sent to url generator.
|
11
|
+
PR [1319](https://github.com/activerecord-hackery/ransack/pull/1319)
|
12
|
+
|
5
13
|
## 3.1.0 - 2022-04-21
|
6
14
|
|
7
15
|
* Fix predicate name in "Using Predicates" documentation page.
|
data/CONTRIBUTING.md
CHANGED
@@ -64,7 +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='6-
|
67
|
+
To install rails other than latest (set in Gemfile): `RAILS='6-1-stable' bundle install`
|
68
68
|
|
69
69
|
4. Begin by running the tests. We only take pull requests with passing tests,
|
70
70
|
and it's great to know that you have a clean slate:
|
data/Gemfile
CHANGED
@@ -3,7 +3,7 @@ gemspec
|
|
3
3
|
|
4
4
|
gem 'rake'
|
5
5
|
|
6
|
-
rails = ENV['RAILS'] || '6-
|
6
|
+
rails = ENV['RAILS'] || '6-1-stable'
|
7
7
|
|
8
8
|
rails_version = case rails
|
9
9
|
when /\// # A path
|
@@ -15,7 +15,7 @@ rails_version = case rails
|
|
15
15
|
end
|
16
16
|
|
17
17
|
gem 'faker', '~> 2.0'
|
18
|
-
gem 'sqlite3',
|
18
|
+
gem 'sqlite3', '~> 1.4.1'
|
19
19
|
gem 'pg', '~> 1.0'
|
20
20
|
gem 'pry', '~> 0.12.2'
|
21
21
|
gem 'byebug'
|
data/docs/yarn.lock
CHANGED
@@ -2347,9 +2347,9 @@ asap@~2.0.3:
|
|
2347
2347
|
integrity sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY=
|
2348
2348
|
|
2349
2349
|
async@^2.6.2:
|
2350
|
-
version "2.6.
|
2351
|
-
resolved "https://registry.yarnpkg.com/async/-/async-2.6.
|
2352
|
-
integrity sha512-
|
2350
|
+
version "2.6.4"
|
2351
|
+
resolved "https://registry.yarnpkg.com/async/-/async-2.6.4.tgz#706b7ff6084664cd7eae713f6f965433b5504221"
|
2352
|
+
integrity sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA==
|
2353
2353
|
dependencies:
|
2354
2354
|
lodash "^4.17.14"
|
2355
2355
|
|
@@ -1 +1,11 @@
|
|
1
|
-
|
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
|
@@ -110,13 +110,7 @@ module Ransack
|
|
110
110
|
def join_sources
|
111
111
|
base, joins = begin
|
112
112
|
alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, @object.table.name, [])
|
113
|
-
constraints =
|
114
|
-
@join_dependency.join_constraints(@object.joins_values, alias_tracker, @object.references_values)
|
115
|
-
elsif ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_0)
|
116
|
-
@join_dependency.join_constraints(@object.joins_values, alias_tracker)
|
117
|
-
else
|
118
|
-
@join_dependency.join_constraints(@object.joins_values, @join_type, alias_tracker)
|
119
|
-
end
|
113
|
+
constraints = @join_dependency.join_constraints(@object.joins_values, alias_tracker, @object.references_values)
|
120
114
|
|
121
115
|
[
|
122
116
|
Arel::SelectManager.new(@object.table),
|
@@ -284,11 +278,7 @@ module Ransack
|
|
284
278
|
join_list = join_nodes + convert_join_strings_to_ast(relation.table, string_joins)
|
285
279
|
|
286
280
|
alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, relation.table.name, join_list)
|
287
|
-
join_dependency =
|
288
|
-
Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins, Arel::Nodes::OuterJoin)
|
289
|
-
else
|
290
|
-
Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins)
|
291
|
-
end
|
281
|
+
join_dependency = Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins, Arel::Nodes::OuterJoin)
|
292
282
|
join_dependency.instance_variable_set(:@alias_tracker, alias_tracker)
|
293
283
|
join_nodes.each do |join|
|
294
284
|
join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1
|
@@ -315,22 +305,13 @@ module Ransack
|
|
315
305
|
end
|
316
306
|
|
317
307
|
def build_association(name, parent = @base, klass = nil)
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
found_association = jd.instance_variable_get(:@join_root).children.last
|
326
|
-
else
|
327
|
-
jd = Polyamorous::JoinDependency.new(
|
328
|
-
parent.base_klass,
|
329
|
-
parent.table,
|
330
|
-
Polyamorous::Join.new(name, @join_type, klass)
|
331
|
-
)
|
332
|
-
found_association = jd.instance_variable_get(:@join_root).children.last
|
333
|
-
end
|
308
|
+
jd = Polyamorous::JoinDependency.new(
|
309
|
+
parent.base_klass,
|
310
|
+
parent.table,
|
311
|
+
Polyamorous::Join.new(name, @join_type, klass),
|
312
|
+
@join_type
|
313
|
+
)
|
314
|
+
found_association = jd.instance_variable_get(:@join_root).children.last
|
334
315
|
|
335
316
|
@associations_pot[found_association] = parent
|
336
317
|
|
@@ -339,11 +320,7 @@ module Ransack
|
|
339
320
|
@join_dependency.instance_variable_get(:@join_root).children.push found_association
|
340
321
|
|
341
322
|
# Builds the arel nodes properly for this association
|
342
|
-
|
343
|
-
@tables_pot[found_association] = @join_dependency.construct_tables_for_association!(jd.instance_variable_get(:@join_root), found_association)
|
344
|
-
else
|
345
|
-
@join_dependency.send(:construct_tables!, jd.instance_variable_get(:@join_root))
|
346
|
-
end
|
323
|
+
@tables_pot[found_association] = @join_dependency.construct_tables_for_association!(jd.instance_variable_get(:@join_root), found_association)
|
347
324
|
|
348
325
|
# Leverage the stashed association functionality in AR
|
349
326
|
@object = @object.joins(jd)
|
@@ -353,22 +330,13 @@ module Ransack
|
|
353
330
|
def extract_joins(association)
|
354
331
|
parent = @join_dependency.instance_variable_get(:@join_root)
|
355
332
|
reflection = association.reflection
|
356
|
-
join_constraints =
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
)
|
364
|
-
else
|
365
|
-
association.join_constraints(
|
366
|
-
parent.table,
|
367
|
-
parent.base_klass,
|
368
|
-
Arel::Nodes::OuterJoin,
|
369
|
-
@join_dependency.instance_variable_get(:@alias_tracker)
|
370
|
-
)
|
371
|
-
end
|
333
|
+
join_constraints = association.join_constraints_with_tables(
|
334
|
+
parent.table,
|
335
|
+
parent.base_klass,
|
336
|
+
Arel::Nodes::OuterJoin,
|
337
|
+
@join_dependency.instance_variable_get(:@alias_tracker),
|
338
|
+
@tables_pot[association]
|
339
|
+
)
|
372
340
|
join_constraints.to_a.flatten
|
373
341
|
end
|
374
342
|
end
|
@@ -47,19 +47,11 @@ module Ransack
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def casted_array?(predicate)
|
50
|
-
|
51
|
-
end
|
52
|
-
|
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
|
50
|
+
predicate.value.is_a?(Array) && predicate.is_a?(Arel::Nodes::Casted)
|
59
51
|
end
|
60
52
|
|
61
53
|
def format_values_for(predicate)
|
62
|
-
|
54
|
+
predicate.value.map do |val|
|
63
55
|
val.is_a?(String) ? Arel::Nodes.build_quoted(val) : val
|
64
56
|
end
|
65
57
|
end
|
data/lib/ransack/constants.rb
CHANGED
@@ -45,9 +45,6 @@ module Ransack
|
|
45
45
|
NOT_EQ_ALL = 'not_eq_all'.freeze
|
46
46
|
CONT = 'cont'.freeze
|
47
47
|
|
48
|
-
RAILS_6_0 = '6.0.0'.freeze
|
49
|
-
RAILS_6_1 = '6.1.0'.freeze
|
50
|
-
|
51
48
|
RANSACK_SLASH_SEARCHES = 'ransack/searches'.freeze
|
52
49
|
RANSACK_SLASH_SEARCHES_SLASH_SEARCH = 'ransack/searches/search'.freeze
|
53
50
|
end
|
data/lib/ransack/version.rb
CHANGED
data/ransack.gemspec
CHANGED
@@ -15,8 +15,8 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.required_ruby_version = '>= 2.7'
|
16
16
|
s.license = 'MIT'
|
17
17
|
|
18
|
-
s.add_dependency 'activerecord', '>= 6.
|
19
|
-
s.add_dependency 'activesupport', '>= 6.
|
18
|
+
s.add_dependency 'activerecord', '>= 6.1.5'
|
19
|
+
s.add_dependency 'activesupport', '>= 6.1.5'
|
20
20
|
s.add_dependency 'i18n'
|
21
21
|
|
22
22
|
s.files = `git ls-files`.split("\n")
|
@@ -3,14 +3,8 @@ module PolyamorousHelper
|
|
3
3
|
Polyamorous::JoinAssociation.new reflection, children, klass
|
4
4
|
end
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
Polyamorous::JoinDependency.new klass, klass.arel_table, associations, Polyamorous::InnerJoin
|
9
|
-
end
|
10
|
-
else
|
11
|
-
def new_join_dependency(klass, associations = {})
|
12
|
-
Polyamorous::JoinDependency.new klass, klass.arel_table, associations
|
13
|
-
end
|
6
|
+
def new_join_dependency(klass, associations = {})
|
7
|
+
Polyamorous::JoinDependency.new klass, klass.arel_table, associations, Polyamorous::InnerJoin
|
14
8
|
end
|
15
9
|
|
16
10
|
def new_join(name, type = Polyamorous::InnerJoin, klass = nil)
|
@@ -770,6 +770,18 @@ module Ransack
|
|
770
770
|
it { should_not match /people\?data%5Bturbo_action%5D=advance/ }
|
771
771
|
end
|
772
772
|
|
773
|
+
describe "#sort_link with host option" do
|
774
|
+
subject { @controller.view_context
|
775
|
+
.sort_link(
|
776
|
+
[:main_app, Person.ransack(sorts: ['name desc'])],
|
777
|
+
:name,
|
778
|
+
host: 'foo', controller: 'people'
|
779
|
+
)
|
780
|
+
}
|
781
|
+
it { should match /href="\/people\?q/ }
|
782
|
+
it { should_not match /href=".*foo/ }
|
783
|
+
end
|
784
|
+
|
773
785
|
describe '#search_form_for with default format' do
|
774
786
|
subject { @controller.view_context
|
775
787
|
.search_form_for(Person.ransack) {} }
|
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: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ernie Miller
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2022-
|
15
|
+
date: 2022-05-09 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: activerecord
|
@@ -20,28 +20,28 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 6.
|
23
|
+
version: 6.1.5
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
27
27
|
requirements:
|
28
28
|
- - ">="
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
version: 6.
|
30
|
+
version: 6.1.5
|
31
31
|
- !ruby/object:Gem::Dependency
|
32
32
|
name: activesupport
|
33
33
|
requirement: !ruby/object:Gem::Requirement
|
34
34
|
requirements:
|
35
35
|
- - ">="
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 6.
|
37
|
+
version: 6.1.5
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
requirements:
|
42
42
|
- - ">="
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
version: 6.
|
44
|
+
version: 6.1.5
|
45
45
|
- !ruby/object:Gem::Dependency
|
46
46
|
name: i18n
|
47
47
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,9 +140,6 @@ files:
|
|
140
140
|
- docs/static/logo/ransack.svg
|
141
141
|
- docs/yarn.lock
|
142
142
|
- lib/polyamorous.rb
|
143
|
-
- lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb
|
144
|
-
- lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb
|
145
|
-
- lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb
|
146
143
|
- lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb
|
147
144
|
- lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb
|
148
145
|
- lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb
|
@@ -258,7 +255,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
258
255
|
- !ruby/object:Gem::Version
|
259
256
|
version: '0'
|
260
257
|
requirements: []
|
261
|
-
rubygems_version: 3.
|
258
|
+
rubygems_version: 3.4.0.dev
|
262
259
|
signing_key:
|
263
260
|
specification_version: 4
|
264
261
|
summary: Object-based searching for Active Record.
|
@@ -1,20 +0,0 @@
|
|
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,79 +0,0 @@
|
|
1
|
-
module Polyamorous
|
2
|
-
module JoinDependencyExtensions
|
3
|
-
# Replaces ActiveRecord::Associations::JoinDependency#build
|
4
|
-
def build(associations, base_klass)
|
5
|
-
associations.map do |name, right|
|
6
|
-
if name.is_a? Join
|
7
|
-
reflection = find_reflection base_klass, name.name
|
8
|
-
reflection.check_validity!
|
9
|
-
reflection.check_eager_loadable!
|
10
|
-
|
11
|
-
klass = if reflection.polymorphic?
|
12
|
-
name.klass || base_klass
|
13
|
-
else
|
14
|
-
reflection.klass
|
15
|
-
end
|
16
|
-
JoinAssociation.new(reflection, build(right, klass), name.klass, name.type)
|
17
|
-
else
|
18
|
-
reflection = find_reflection base_klass, name
|
19
|
-
reflection.check_validity!
|
20
|
-
reflection.check_eager_loadable!
|
21
|
-
|
22
|
-
if reflection.polymorphic?
|
23
|
-
raise ActiveRecord::EagerLoadPolymorphicError.new(reflection)
|
24
|
-
end
|
25
|
-
JoinAssociation.new(reflection, build(right, reflection.klass))
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def join_constraints(joins_to_add, alias_tracker)
|
31
|
-
@alias_tracker = alias_tracker
|
32
|
-
|
33
|
-
construct_tables!(join_root)
|
34
|
-
joins = make_join_constraints(join_root, join_type)
|
35
|
-
|
36
|
-
joins.concat joins_to_add.flat_map { |oj|
|
37
|
-
construct_tables!(oj.join_root)
|
38
|
-
if join_root.match?(oj.join_root) && join_root.table.name == oj.join_root.table.name
|
39
|
-
walk join_root, oj.join_root, oj.join_type
|
40
|
-
else
|
41
|
-
make_join_constraints(oj.join_root, oj.join_type)
|
42
|
-
end
|
43
|
-
}
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
def make_constraints(parent, child, join_type = Arel::Nodes::OuterJoin)
|
48
|
-
foreign_table = parent.table
|
49
|
-
foreign_klass = parent.base_klass
|
50
|
-
join_type = child.join_type || join_type if join_type == Arel::Nodes::InnerJoin
|
51
|
-
joins = child.join_constraints(foreign_table, foreign_klass, join_type, alias_tracker)
|
52
|
-
joins.concat child.children.flat_map { |c| make_constraints(child, c, join_type) }
|
53
|
-
end
|
54
|
-
|
55
|
-
module ClassMethods
|
56
|
-
# Prepended before ActiveRecord::Associations::JoinDependency#walk_tree
|
57
|
-
#
|
58
|
-
def walk_tree(associations, hash)
|
59
|
-
case associations
|
60
|
-
when TreeNode
|
61
|
-
associations.add_to_tree(hash)
|
62
|
-
when Hash
|
63
|
-
associations.each do |k, v|
|
64
|
-
cache =
|
65
|
-
if TreeNode === k
|
66
|
-
k.add_to_tree(hash)
|
67
|
-
else
|
68
|
-
hash[k] ||= {}
|
69
|
-
end
|
70
|
-
walk_tree(v, cache)
|
71
|
-
end
|
72
|
-
else
|
73
|
-
super(associations, hash)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
79
|
-
end
|