ransack 2.3.2 → 2.4.0
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/.travis.yml +14 -14
- data/CHANGELOG.md +13 -0
- data/CONTRIBUTING.md +11 -6
- data/Gemfile +2 -2
- data/README.md +5 -4
- data/{polyamorous/lib → lib}/polyamorous/activerecord_5.2_ruby_2/join_association.rb +4 -0
- data/{polyamorous/lib → lib}/polyamorous/activerecord_5.2_ruby_2/join_dependency.rb +0 -0
- data/lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb +11 -0
- data/{polyamorous/lib → lib}/polyamorous/activerecord_6.0_ruby_2/join_association.rb +0 -1
- data/{polyamorous/lib → lib}/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +0 -1
- data/{polyamorous/lib → lib}/polyamorous/activerecord_6.0_ruby_2/reflection.rb +0 -1
- data/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +74 -0
- data/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +93 -0
- data/{polyamorous/lib → lib}/polyamorous/activerecord_6.1_ruby_2/reflection.rb +0 -1
- data/{polyamorous/lib → lib}/polyamorous/join.rb +0 -0
- data/{polyamorous/lib → lib/polyamorous}/polyamorous.rb +0 -0
- data/{polyamorous/lib → lib}/polyamorous/swapping_reflection_class.rb +0 -0
- data/{polyamorous/lib → lib}/polyamorous/tree_node.rb +0 -0
- data/lib/ransack.rb +1 -1
- data/lib/ransack/adapters/active_record/context.rb +44 -13
- data/lib/ransack/adapters/active_record/ransack/context.rb +1 -0
- data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +10 -3
- data/lib/ransack/constants.rb +1 -0
- data/lib/ransack/nodes/grouping.rb +1 -1
- data/lib/ransack/search.rb +1 -0
- data/lib/ransack/translate.rb +3 -3
- data/lib/ransack/version.rb +1 -1
- data/ransack.gemspec +4 -11
- data/spec/{ransack → polyamorous}/join_association_spec.rb +7 -0
- data/spec/{ransack → polyamorous}/join_dependency_spec.rb +0 -0
- data/spec/{ransack → polyamorous}/join_spec.rb +0 -0
- data/spec/ransack/adapters/active_record/base_spec.rb +3 -3
- data/spec/ransack/adapters/active_record/context_spec.rb +19 -17
- data/spec/ransack/search_spec.rb +55 -7
- data/spec/spec_helper.rb +1 -0
- data/spec/support/schema.rb +3 -0
- metadata +25 -41
- data/polyamorous/lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb +0 -12
- data/polyamorous/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +0 -2
- data/polyamorous/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +0 -2
- data/polyamorous/lib/polyamorous/version.rb +0 -3
- data/polyamorous/polyamorous.gemspec +0 -27
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f5cd517575121b1f2c1041501645a95680a4efbe82c0b2d6c74e079d080cda29
|
|
4
|
+
data.tar.gz: f927c47bfc28f15d7a24eb2761ae1d003ff18912c1c91e7716ed2628f9012ccc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: be9485ce5f692f990c7b8c5b59c961311783fafb845c3580dbd0d08eb62e24c1067da75e98f24cd4553e7db21a15531ca2943c1633566995a6e7c64d6310d2f2
|
|
7
|
+
data.tar.gz: 3fbca263c9e5f399695e9cc69e50762fc72875860ad495c04368ff84d90c68100d5ca1b6db22aa17a5c2c52efccd4d99bc0c29b5485ae6608390a606fd35ac18
|
data/.travis.yml
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
+
branches: master
|
|
2
|
+
|
|
1
3
|
language: ruby
|
|
2
4
|
|
|
3
5
|
rvm:
|
|
4
|
-
- 2.6.
|
|
6
|
+
- 2.6.6
|
|
5
7
|
|
|
6
8
|
services:
|
|
7
9
|
- mysql
|
|
8
10
|
|
|
9
11
|
env:
|
|
12
|
+
- RAILS=v6.1.0.rc1 DB=sqlite3
|
|
13
|
+
- RAILS=v6.1.0.rc1 DB=mysql
|
|
14
|
+
- RAILS=v6.1.0.rc1 DB=postgres
|
|
15
|
+
|
|
16
|
+
- RAILS=v6.0.3 DB=sqlite3
|
|
17
|
+
- RAILS=v6.0.3 DB=mysql
|
|
18
|
+
- RAILS=v6.0.3 DB=postgres
|
|
19
|
+
|
|
10
20
|
- RAILS=6-0-stable DB=sqlite3
|
|
11
21
|
- RAILS=6-0-stable DB=mysql
|
|
12
22
|
- RAILS=6-0-stable DB=postgres
|
|
13
23
|
|
|
14
|
-
- RAILS=v6.0.0 DB=sqlite3
|
|
15
|
-
- RAILS=v6.0.0 DB=mysql
|
|
16
|
-
- RAILS=v6.0.0 DB=postgres
|
|
17
|
-
|
|
18
24
|
- RAILS=5-2-stable DB=sqlite3
|
|
19
25
|
- RAILS=5-2-stable DB=mysql
|
|
20
26
|
- RAILS=5-2-stable DB=postgres
|
|
21
27
|
|
|
22
|
-
- RAILS=v5.2.
|
|
23
|
-
- RAILS=v5.2.
|
|
24
|
-
- RAILS=v5.2.
|
|
25
|
-
|
|
26
|
-
matrix:
|
|
27
|
-
allow_failures:
|
|
28
|
-
- env: RAILS=6-0-stable DB=sqlite3
|
|
29
|
-
- env: RAILS=6-0-stable DB=mysql
|
|
30
|
-
- env: RAILS=6-0-stable DB=postgres
|
|
28
|
+
- RAILS=v5.2.4 DB=sqlite3
|
|
29
|
+
- RAILS=v5.2.4 DB=mysql
|
|
30
|
+
- RAILS=v5.2.4 DB=postgres
|
|
31
31
|
|
|
32
32
|
before_script:
|
|
33
33
|
- if [ "$DB" = "mysql" ];
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 2.4.0 - 2020-11-27
|
|
4
|
+
|
|
5
|
+
*
|
|
6
|
+
PR []()
|
|
7
|
+
|
|
8
|
+
* Support ActiveRecord 6.1.0.rc1.
|
|
9
|
+
PR [1172](https://github.com/activerecord-hackery/ransack/pull/1172)
|
|
10
|
+
|
|
11
|
+
* Fix for ActiveRecord 5.2.4 (note security fix in 5.2.4.2 for ActiveView's escape_javascript CVE-2020-5267 for all earlier versions)
|
|
12
|
+
|
|
13
|
+
* Drop support for ActiveRecord older than 5.2.4.
|
|
14
|
+
PR [1166](https://github.com/activerecord-hackery/ransack/pull/1166)
|
|
15
|
+
|
|
3
16
|
## 2.3.2 - 2020-01-11
|
|
4
17
|
|
|
5
18
|
* Breakfix to bump Polyamorous
|
data/CONTRIBUTING.md
CHANGED
|
@@ -64,6 +64,9 @@ 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
70
|
|
|
68
71
|
4. Begin by running the tests. We only take pull requests with passing tests,
|
|
69
72
|
and it's great to know that you have a clean slate:
|
|
@@ -84,16 +87,18 @@ Here's a quick guide:
|
|
|
84
87
|
$ mysql -u root
|
|
85
88
|
mysql> create database ransack;
|
|
86
89
|
|
|
87
|
-
|
|
90
|
+
The test suite runs by default
|
|
91
|
+
|
|
92
|
+
To run only the tests in a particular file: `bundle exec rspec <path/to/filename>`
|
|
88
93
|
|
|
89
|
-
$ rspec spec/ransack/search_spec.rb
|
|
94
|
+
$ bundle exec rspec spec/ransack/search_spec.rb
|
|
90
95
|
|
|
91
|
-
To run a single test in that file: `rspec <path/to/filename> -e "test name"`
|
|
96
|
+
To run a single test in that file: `bundle exec rspec <path/to/filename> -e "test name"`
|
|
92
97
|
|
|
93
|
-
$ rspec spec/ransack/search_spec.rb -e "accepts a context option"
|
|
98
|
+
$ bundle exec rspec spec/ransack/search_spec.rb -e "accepts a context option"
|
|
94
99
|
|
|
95
|
-
5. Hack away! Please use Ruby features that are compatible down to Ruby
|
|
96
|
-
Since version 1
|
|
100
|
+
5. Hack away! Please use Ruby features that are compatible down to Ruby 2.3.
|
|
101
|
+
Since version 2.3.1, Ransack no longer maintains Ruby 2.2 compatibility.
|
|
97
102
|
|
|
98
103
|
6. Add tests for your changes. Only refactoring and documentation changes
|
|
99
104
|
require no new tests. If you are adding functionality or fixing a bug, we
|
data/Gemfile
CHANGED
|
@@ -14,10 +14,10 @@ rails_version = case rails
|
|
|
14
14
|
rails
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
gem 'faker', '~> 0
|
|
17
|
+
gem 'faker', '~> 1.0'
|
|
18
18
|
gem 'sqlite3', ::Gem::Version.new(rails_version) >= ::Gem::Version.new('6-0-stable') ? '~> 1.4.1' : '~> 1.3.3'
|
|
19
19
|
gem 'pg', '~> 1.0'
|
|
20
|
-
gem 'pry', '0.
|
|
20
|
+
gem 'pry', '~> 0.12.2'
|
|
21
21
|
gem 'byebug'
|
|
22
22
|
|
|
23
23
|
case rails
|
data/README.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# 
|
|
2
2
|
|
|
3
|
+
**MAINTAINER WANTED**
|
|
4
|
+
|
|
5
|
+
Please see the [Maintainer wanted issue](https://github.com/activerecord-hackery/ransack/issues/1159) if you are interested.
|
|
6
|
+
|
|
3
7
|
[](https://travis-ci.org/activerecord-hackery/ransack)
|
|
4
8
|
[](http://badge.fury.io/rb/ransack)
|
|
5
9
|
[](https://codeclimate.com/github/activerecord-hackery/ransack)
|
|
@@ -437,13 +441,10 @@ List of all possible predicates
|
|
|
437
441
|
| `*_lteq_any` | Less than or equal to any | |
|
|
438
442
|
| `*_gt_any` | Greater than any | |
|
|
439
443
|
| `*_gteq_any` | Greater than or equal to any | |
|
|
440
|
-
| `*_matches_any` | `*_does_not_match_any` | same as above but with `LIKE` |
|
|
441
444
|
| `*_lt_all` | Less than all | SQL: `col < value1 AND col < value2` |
|
|
442
445
|
| `*_lteq_all` | Less than or equal to all | |
|
|
443
446
|
| `*_gt_all` | Greater than all | |
|
|
444
447
|
| `*_gteq_all` | Greater than or equal to all | |
|
|
445
|
-
| `*_matches_all` | Matches all | same as above but with `LIKE` |
|
|
446
|
-
| `*_does_not_match_all` | Does not match all | |
|
|
447
448
|
| `*_not_eq_all` | none of values in a set | |
|
|
448
449
|
| `*_start` | Starts with | SQL: `col LIKE 'value%'` |
|
|
449
450
|
| `*_not_start` | Does not start with | |
|
|
@@ -463,7 +464,7 @@ List of all possible predicates
|
|
|
463
464
|
| `*_not_cont` | Does not contain |
|
|
464
465
|
| `*_not_cont_any` | Does not contain any of | |
|
|
465
466
|
| `*_not_cont_all` | Does not contain all of | |
|
|
466
|
-
| `*_i_cont` | Contains value with case insensitive | uses `
|
|
467
|
+
| `*_i_cont` | Contains value with case insensitive | uses `ILIKE` |
|
|
467
468
|
| `*_i_cont_any` | Contains any of values with case insensitive | |
|
|
468
469
|
| `*_i_cont_all` | Contains all of values with case insensitive | |
|
|
469
470
|
| `*_not_i_cont` | Does not contain with case insensitive |
|
|
File without changes
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
|
|
20
|
+
# Same as #join_constraints, but instead of constructing tables from the
|
|
21
|
+
# given block, uses the ones passed
|
|
22
|
+
def join_constraints_with_tables(foreign_table, foreign_klass, join_type, alias_tracker, tables)
|
|
23
|
+
joins = []
|
|
24
|
+
chain = []
|
|
25
|
+
|
|
26
|
+
reflection.chain.each.with_index do |reflection, i|
|
|
27
|
+
table = tables[i]
|
|
28
|
+
|
|
29
|
+
@table ||= table
|
|
30
|
+
chain << [reflection, table]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# The chain starts with the target table, but we want to end with it here (makes
|
|
34
|
+
# more sense in this context), so we reverse
|
|
35
|
+
chain.reverse_each do |reflection, table|
|
|
36
|
+
klass = reflection.klass
|
|
37
|
+
|
|
38
|
+
join_scope = reflection.join_scope(table, foreign_table, foreign_klass)
|
|
39
|
+
|
|
40
|
+
unless join_scope.references_values.empty?
|
|
41
|
+
join_dependency = join_scope.construct_join_dependency(
|
|
42
|
+
join_scope.eager_load_values | join_scope.includes_values, Arel::Nodes::OuterJoin
|
|
43
|
+
)
|
|
44
|
+
join_scope.joins!(join_dependency)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
arel = join_scope.arel(alias_tracker.aliases)
|
|
48
|
+
nodes = arel.constraints.first
|
|
49
|
+
|
|
50
|
+
if nodes.is_a?(Arel::Nodes::And)
|
|
51
|
+
others = nodes.children.extract! do |node|
|
|
52
|
+
!Arel.fetch_attribute(node) { |attr| attr.relation.name == table.name }
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
joins << table.create_join(table, table.create_on(nodes), join_type)
|
|
57
|
+
|
|
58
|
+
if others && !others.empty?
|
|
59
|
+
joins.concat arel.join_sources
|
|
60
|
+
append_constraints(joins.last, others)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# The current table in this iteration becomes the foreign table in the next
|
|
64
|
+
foreign_table, foreign_klass = table, klass
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
joins
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def ==(other)
|
|
71
|
+
base_klass == other.base_klass
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# active_record_6.1_ruby_2/join_dependency.rb
|
|
2
|
+
module Polyamorous
|
|
3
|
+
module JoinDependencyExtensions
|
|
4
|
+
# Replaces ActiveRecord::Associations::JoinDependency#build
|
|
5
|
+
def build(associations, base_klass)
|
|
6
|
+
associations.map do |name, right|
|
|
7
|
+
if name.is_a? Join
|
|
8
|
+
reflection = find_reflection base_klass, name.name
|
|
9
|
+
reflection.check_validity!
|
|
10
|
+
reflection.check_eager_loadable!
|
|
11
|
+
|
|
12
|
+
klass = if reflection.polymorphic?
|
|
13
|
+
name.klass || base_klass
|
|
14
|
+
else
|
|
15
|
+
reflection.klass
|
|
16
|
+
end
|
|
17
|
+
JoinAssociation.new(reflection, build(right, klass), name.klass, name.type)
|
|
18
|
+
else
|
|
19
|
+
reflection = find_reflection base_klass, name
|
|
20
|
+
reflection.check_validity!
|
|
21
|
+
reflection.check_eager_loadable!
|
|
22
|
+
|
|
23
|
+
if reflection.polymorphic?
|
|
24
|
+
raise ActiveRecord::EagerLoadPolymorphicError.new(reflection)
|
|
25
|
+
end
|
|
26
|
+
JoinAssociation.new(reflection, build(right, reflection.klass))
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def join_constraints(joins_to_add, alias_tracker, references)
|
|
32
|
+
@alias_tracker = alias_tracker
|
|
33
|
+
@joined_tables = {}
|
|
34
|
+
@references = {}
|
|
35
|
+
|
|
36
|
+
references.each do |table_name|
|
|
37
|
+
@references[table_name.to_sym] = table_name if table_name.is_a?(String)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
joins = make_join_constraints(join_root, join_type)
|
|
41
|
+
|
|
42
|
+
joins.concat joins_to_add.flat_map { |oj|
|
|
43
|
+
if join_root.match?(oj.join_root) && join_root.table.name == oj.join_root.table.name
|
|
44
|
+
walk join_root, oj.join_root, oj.join_type
|
|
45
|
+
else
|
|
46
|
+
make_join_constraints(oj.join_root, oj.join_type)
|
|
47
|
+
end
|
|
48
|
+
}
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def construct_tables_for_association!(join_root, association)
|
|
52
|
+
tables = table_aliases_for(join_root, association)
|
|
53
|
+
association.table = tables.first
|
|
54
|
+
tables
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
|
|
59
|
+
def table_aliases_for(parent, node)
|
|
60
|
+
node.reflection.chain.map { |reflection|
|
|
61
|
+
alias_tracker.aliased_table_for(reflection.klass.arel_table) do
|
|
62
|
+
root = reflection == node.reflection
|
|
63
|
+
name = reflection.alias_candidate(parent.table_name)
|
|
64
|
+
root ? name : "#{name}_join"
|
|
65
|
+
end
|
|
66
|
+
}
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
module ClassMethods
|
|
70
|
+
# Prepended before ActiveRecord::Associations::JoinDependency#walk_tree
|
|
71
|
+
#
|
|
72
|
+
def walk_tree(associations, hash)
|
|
73
|
+
case associations
|
|
74
|
+
when TreeNode
|
|
75
|
+
associations.add_to_tree(hash)
|
|
76
|
+
when Hash
|
|
77
|
+
associations.each do |k, v|
|
|
78
|
+
cache =
|
|
79
|
+
if TreeNode === k
|
|
80
|
+
k.add_to_tree(hash)
|
|
81
|
+
else
|
|
82
|
+
hash[k] ||= {}
|
|
83
|
+
end
|
|
84
|
+
walk_tree(v, cache)
|
|
85
|
+
end
|
|
86
|
+
else
|
|
87
|
+
super(associations, hash)
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
end
|
|
93
|
+
end
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
data/lib/ransack.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
require 'ransack/context'
|
|
2
|
-
require 'polyamorous'
|
|
2
|
+
require 'polyamorous/polyamorous'
|
|
3
3
|
|
|
4
4
|
module Ransack
|
|
5
5
|
module Adapters
|
|
@@ -99,7 +99,9 @@ module Ransack
|
|
|
99
99
|
def join_sources
|
|
100
100
|
base, joins = begin
|
|
101
101
|
alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, @object.table.name, [])
|
|
102
|
-
constraints = if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::
|
|
102
|
+
constraints = if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_1_ALPHA)
|
|
103
|
+
@join_dependency.join_constraints(@object.joins_values, alias_tracker, @object.references_values)
|
|
104
|
+
elsif ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_0)
|
|
103
105
|
@join_dependency.join_constraints(@object.joins_values, alias_tracker)
|
|
104
106
|
else
|
|
105
107
|
@join_dependency.join_constraints(@object.joins_values, @join_type, alias_tracker)
|
|
@@ -172,16 +174,31 @@ module Ransack
|
|
|
172
174
|
private
|
|
173
175
|
|
|
174
176
|
def extract_correlated_key(join_root)
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
177
|
+
case join_root
|
|
178
|
+
when Arel::Nodes::OuterJoin
|
|
179
|
+
# one of join_root.right/join_root.left is expected to be Arel::Nodes::On
|
|
180
|
+
if join_root.right.is_a?(Arel::Nodes::On)
|
|
181
|
+
extract_correlated_key(join_root.right.expr)
|
|
182
|
+
elsif join_root.left.is_a?(Arel::Nodes::On)
|
|
183
|
+
extract_correlated_key(join_root.left.expr)
|
|
184
|
+
else
|
|
185
|
+
raise 'Ransack encountered an unexpected arel structure'
|
|
186
|
+
end
|
|
187
|
+
when Arel::Nodes::Equality
|
|
188
|
+
pk = primary_key
|
|
189
|
+
if join_root.left == pk
|
|
190
|
+
join_root.right
|
|
191
|
+
elsif join_root.right == pk
|
|
192
|
+
join_root.left
|
|
193
|
+
else
|
|
194
|
+
nil
|
|
195
|
+
end
|
|
196
|
+
when Arel::Nodes::And
|
|
197
|
+
extract_correlated_key(join_root.left) || extract_correlated_key(join_root.right)
|
|
183
198
|
else
|
|
184
|
-
|
|
199
|
+
# eg parent was Arel::Nodes::And and the evaluated side was one of
|
|
200
|
+
# Arel::Nodes::Grouping or MultiTenant::TenantEnforcementClause
|
|
201
|
+
nil
|
|
185
202
|
end
|
|
186
203
|
end
|
|
187
204
|
|
|
@@ -310,7 +327,11 @@ module Ransack
|
|
|
310
327
|
@join_dependency.instance_variable_get(:@join_root).children.push found_association
|
|
311
328
|
|
|
312
329
|
# Builds the arel nodes properly for this association
|
|
313
|
-
|
|
330
|
+
if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_1_ALPHA)
|
|
331
|
+
@tables_pot[found_association] = @join_dependency.construct_tables_for_association!(jd.instance_variable_get(:@join_root), found_association)
|
|
332
|
+
else
|
|
333
|
+
@join_dependency.send(:construct_tables!, jd.instance_variable_get(:@join_root))
|
|
334
|
+
end
|
|
314
335
|
|
|
315
336
|
# Leverage the stashed association functionality in AR
|
|
316
337
|
@object = @object.joins(jd)
|
|
@@ -320,12 +341,22 @@ module Ransack
|
|
|
320
341
|
def extract_joins(association)
|
|
321
342
|
parent = @join_dependency.instance_variable_get(:@join_root)
|
|
322
343
|
reflection = association.reflection
|
|
323
|
-
join_constraints =
|
|
344
|
+
join_constraints = if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_1_ALPHA)
|
|
345
|
+
association.join_constraints_with_tables(
|
|
346
|
+
parent.table,
|
|
347
|
+
parent.base_klass,
|
|
348
|
+
Arel::Nodes::OuterJoin,
|
|
349
|
+
@join_dependency.instance_variable_get(:@alias_tracker),
|
|
350
|
+
@tables_pot[association]
|
|
351
|
+
)
|
|
352
|
+
else
|
|
353
|
+
association.join_constraints(
|
|
324
354
|
parent.table,
|
|
325
355
|
parent.base_klass,
|
|
326
356
|
Arel::Nodes::OuterJoin,
|
|
327
357
|
@join_dependency.instance_variable_get(:@alias_tracker)
|
|
328
358
|
)
|
|
359
|
+
end
|
|
329
360
|
join_constraints.to_a.flatten
|
|
330
361
|
end
|
|
331
362
|
end
|
|
@@ -28,6 +28,7 @@ module Ransack
|
|
|
28
28
|
@join_type = options[:join_type] || Polyamorous::OuterJoin
|
|
29
29
|
@search_key = options[:search_key] || Ransack.options[:search_key]
|
|
30
30
|
@associations_pot = {}
|
|
31
|
+
@tables_pot = {}
|
|
31
32
|
@lock_associations = []
|
|
32
33
|
|
|
33
34
|
@base = @join_dependency.instance_variable_get(:@join_root)
|
|
@@ -47,12 +47,19 @@ module Ransack
|
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
def casted_array?(predicate)
|
|
50
|
-
predicate.respond_to?(:
|
|
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
|
|
51
52
|
end
|
|
52
53
|
|
|
53
54
|
def format_values_for(predicate)
|
|
54
|
-
predicate.
|
|
55
|
-
|
|
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
|
|
60
|
+
|
|
61
|
+
value.map do |val|
|
|
62
|
+
val.is_a?(String) ? Arel::Nodes.build_quoted(val) : val
|
|
56
63
|
end
|
|
57
64
|
end
|
|
58
65
|
|
data/lib/ransack/constants.rb
CHANGED
|
@@ -108,7 +108,7 @@ module Ransack
|
|
|
108
108
|
alias :g= :groupings=
|
|
109
109
|
|
|
110
110
|
def method_missing(method_id, *args)
|
|
111
|
-
method_name = method_id.to_s
|
|
111
|
+
method_name = method_id.to_s.dup
|
|
112
112
|
writer = method_name.sub!(/\=$/, ''.freeze)
|
|
113
113
|
if attribute_method?(method_name)
|
|
114
114
|
if writer
|
data/lib/ransack/search.rb
CHANGED
|
@@ -18,6 +18,7 @@ module Ransack
|
|
|
18
18
|
params = params.to_unsafe_h if params.respond_to?(:to_unsafe_h)
|
|
19
19
|
if params.is_a? Hash
|
|
20
20
|
params = params.dup
|
|
21
|
+
params = params.transform_values { |v| v.is_a?(String) ? v.strip : v }
|
|
21
22
|
params.delete_if { |k, v| [*v].all?{ |i| i.blank? && i != false } }
|
|
22
23
|
else
|
|
23
24
|
params = {}
|
data/lib/ransack/translate.rb
CHANGED
|
@@ -50,7 +50,7 @@ module Ransack
|
|
|
50
50
|
|
|
51
51
|
defaults << options.delete(:default) if options[:default]
|
|
52
52
|
options.reverse_merge! count: 1, default: defaults
|
|
53
|
-
I18n.translate(defaults.shift, options.merge(interpolations))
|
|
53
|
+
I18n.translate(defaults.shift, **options.merge(interpolations))
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
def association(key, options = {})
|
|
@@ -67,7 +67,7 @@ module Ransack
|
|
|
67
67
|
end
|
|
68
68
|
defaults << context.traverse(key).model_name.human
|
|
69
69
|
options = { :count => 1, :default => defaults }
|
|
70
|
-
I18n.translate(defaults.shift, options)
|
|
70
|
+
I18n.translate(defaults.shift, **options)
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
private
|
|
@@ -83,7 +83,7 @@ module Ransack
|
|
|
83
83
|
options = { count: 1, default: defaults }
|
|
84
84
|
interpolations = build_interpolations(associated_class)
|
|
85
85
|
|
|
86
|
-
I18n.translate(defaults.shift, options.merge(interpolations))
|
|
86
|
+
I18n.translate(defaults.shift, **options.merge(interpolations))
|
|
87
87
|
end
|
|
88
88
|
|
|
89
89
|
def default_attribute_name
|
data/lib/ransack/version.rb
CHANGED
data/ransack.gemspec
CHANGED
|
@@ -14,19 +14,12 @@ Gem::Specification.new do |s|
|
|
|
14
14
|
s.required_ruby_version = '>= 2.3'
|
|
15
15
|
s.license = 'MIT'
|
|
16
16
|
|
|
17
|
-
s.add_dependency 'activerecord', '>= 5.2.
|
|
18
|
-
s.add_dependency 'activesupport', '>= 5.2.
|
|
17
|
+
s.add_dependency 'activerecord', '>= 5.2.4'
|
|
18
|
+
s.add_dependency 'activesupport', '>= 5.2.4'
|
|
19
19
|
s.add_dependency 'i18n'
|
|
20
|
-
s.add_dependency 'polyamorous', Ransack::VERSION.to_s
|
|
21
20
|
|
|
22
21
|
s.files = `git ls-files`.split("\n")
|
|
23
|
-
|
|
24
|
-
s.
|
|
25
|
-
.split("\n")
|
|
26
|
-
|
|
27
|
-
s.executables = `git ls-files -- bin/*`
|
|
28
|
-
.split("\n")
|
|
29
|
-
.map { |f| File.basename(f) }
|
|
30
|
-
|
|
22
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
23
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
31
24
|
s.require_paths = ["lib"]
|
|
32
25
|
end
|
|
@@ -10,6 +10,13 @@ module Polyamorous
|
|
|
10
10
|
new_join_association(reflection, parent.children, Article)
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
subject { new_join_association(reflection, parent.children, Person) }
|
|
14
|
+
|
|
15
|
+
it 'respects polymorphism on equality test' do
|
|
16
|
+
expect(subject).to eq new_join_association(reflection, parent.children, Person)
|
|
17
|
+
expect(subject).not_to eq new_join_association(reflection, parent.children, Article)
|
|
18
|
+
end
|
|
19
|
+
|
|
13
20
|
it 'leaves the orginal reflection intact for thread safety' do
|
|
14
21
|
reflection.instance_variable_set(:@klass, Article)
|
|
15
22
|
join_association
|
|
File without changes
|
|
File without changes
|
|
@@ -143,14 +143,12 @@ module Ransack
|
|
|
143
143
|
it 'removes redundant joins from top query' do
|
|
144
144
|
s = Article.ransack(tags_name_not_eq: "Fantasy")
|
|
145
145
|
sql = s.result.to_sql
|
|
146
|
-
|
|
147
146
|
expect(sql).to_not include('LEFT OUTER JOIN')
|
|
148
147
|
end
|
|
149
148
|
|
|
150
149
|
it 'handles != for single values' do
|
|
151
150
|
s = Article.ransack(tags_name_not_eq: "Fantasy")
|
|
152
151
|
articles = s.result.to_a
|
|
153
|
-
|
|
154
152
|
expect(articles).to include marco
|
|
155
153
|
expect(articles).to_not include arthur
|
|
156
154
|
end
|
|
@@ -267,10 +265,12 @@ module Ransack
|
|
|
267
265
|
# end
|
|
268
266
|
|
|
269
267
|
it 'creates ransack attributes' do
|
|
268
|
+
person = Person.create!(name: 'Aric Smith')
|
|
269
|
+
|
|
270
270
|
s = Person.ransack(reversed_name_eq: 'htimS cirA')
|
|
271
271
|
expect(s.result.size).to eq(1)
|
|
272
272
|
|
|
273
|
-
expect(s.result.first).to eq
|
|
273
|
+
expect(s.result.first).to eq person
|
|
274
274
|
end
|
|
275
275
|
|
|
276
276
|
it 'can be accessed through associations' do
|
|
@@ -79,6 +79,25 @@ module Ransack
|
|
|
79
79
|
expect(constraint.right.relation.name).to eql 'people'
|
|
80
80
|
expect(constraint.right.name).to eql 'id'
|
|
81
81
|
end
|
|
82
|
+
|
|
83
|
+
it 'build correlated subquery for multiple conditions (default scope)' do
|
|
84
|
+
search = Search.new(Person, { comments_body_not_eq: 'some_title'})
|
|
85
|
+
|
|
86
|
+
# Was
|
|
87
|
+
# SELECT "people".* FROM "people" WHERE "people"."id" NOT IN (
|
|
88
|
+
# SELECT "comments"."disabled" FROM "comments"
|
|
89
|
+
# WHERE "comments"."disabled" = "people"."id"
|
|
90
|
+
# AND NOT ("comments"."body" != 'some_title')
|
|
91
|
+
# ) ORDER BY "people"."id" DESC
|
|
92
|
+
# Should Be
|
|
93
|
+
# SELECT "people".* FROM "people" WHERE "people"."id" NOT IN (
|
|
94
|
+
# SELECT "comments"."person_id" FROM "comments"
|
|
95
|
+
# WHERE "comments"."person_id" = "people"."id"
|
|
96
|
+
# AND NOT ("comments"."body" != 'some_title')
|
|
97
|
+
# ) ORDER BY "people"."id" DESC
|
|
98
|
+
|
|
99
|
+
expect(search.result.to_sql).to match /.comments.\..person_id. = .people.\..id./
|
|
100
|
+
end
|
|
82
101
|
end
|
|
83
102
|
|
|
84
103
|
describe 'sharing context across searches' do
|
|
@@ -91,23 +110,6 @@ module Ransack
|
|
|
91
110
|
context: shared_context)
|
|
92
111
|
end
|
|
93
112
|
|
|
94
|
-
describe '#join_associations', if: AR_version <= '4.0' do
|
|
95
|
-
it 'returns dependent join associations for all searches run
|
|
96
|
-
against the context' do
|
|
97
|
-
parents, children = shared_context.join_associations
|
|
98
|
-
|
|
99
|
-
expect(children.aliased_table_name).to eq "children_people"
|
|
100
|
-
expect(parents.aliased_table_name).to eq "parents_people"
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
it 'can be rejoined to execute a valid query' do
|
|
104
|
-
parents, children = shared_context.join_associations
|
|
105
|
-
|
|
106
|
-
expect { Person.joins(parents).joins(children).to_a }
|
|
107
|
-
.to_not raise_error
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
|
|
111
113
|
describe '#join_sources' do
|
|
112
114
|
it 'returns dependent arel join nodes for all searches run against
|
|
113
115
|
the context' do
|
data/spec/ransack/search_spec.rb
CHANGED
|
@@ -20,6 +20,12 @@ module Ransack
|
|
|
20
20
|
Search.new(Person, name_eq: 'foobar')
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
+
it 'strip leading & trailing whitespace before building' do
|
|
24
|
+
expect_any_instance_of(Search).to receive(:build)
|
|
25
|
+
.with({ 'name_eq' => 'foobar' })
|
|
26
|
+
Search.new(Person, name_eq: ' foobar ')
|
|
27
|
+
end
|
|
28
|
+
|
|
23
29
|
it 'removes empty suffixed conditions before building' do
|
|
24
30
|
expect_any_instance_of(Search).to receive(:build).with({})
|
|
25
31
|
Search.new(Person, name_eq_any: [''])
|
|
@@ -109,6 +115,43 @@ module Ransack
|
|
|
109
115
|
expect(s.result.to_sql).to include 'published'
|
|
110
116
|
end
|
|
111
117
|
|
|
118
|
+
# The failure/oversight in Ransack::Nodes::Condition#arel_predicate or deeper is beyond my understanding of the structures
|
|
119
|
+
it 'preserves (inverts) default scope and conditions for negative subqueries' do
|
|
120
|
+
# the positive case (published_articles_title_eq) is
|
|
121
|
+
# SELECT "people".* FROM "people"
|
|
122
|
+
# LEFT OUTER JOIN "articles" ON "articles"."person_id" = "people"."id"
|
|
123
|
+
# AND "articles"."published" = 't'
|
|
124
|
+
# AND ('default_scope' = 'default_scope')
|
|
125
|
+
# WHERE "articles"."title" = 'Test' ORDER BY "people"."id" DESC
|
|
126
|
+
#
|
|
127
|
+
# negative case was
|
|
128
|
+
# SELECT "people".* FROM "people" WHERE "people"."id" NOT IN (
|
|
129
|
+
# SELECT "articles"."person_id" FROM "articles"
|
|
130
|
+
# WHERE "articles"."person_id" = "people"."id"
|
|
131
|
+
# AND NOT ("articles"."title" != 'Test')
|
|
132
|
+
# ) ORDER BY "people"."id" DESC
|
|
133
|
+
#
|
|
134
|
+
# Should have been like
|
|
135
|
+
# SELECT "people".* FROM "people" WHERE "people"."id" NOT IN (
|
|
136
|
+
# SELECT "articles"."person_id" FROM "articles"
|
|
137
|
+
# WHERE "articles"."person_id" = "people"."id"
|
|
138
|
+
# AND "articles"."title" = 'Test' AND "articles"."published" = 't' AND ('default_scope' = 'default_scope')
|
|
139
|
+
# ) ORDER BY "people"."id" DESC
|
|
140
|
+
#
|
|
141
|
+
# With tenanting (eg default_scope with column reference), NOT IN should be like
|
|
142
|
+
# SELECT "people".* FROM "people" WHERE "people"."tenant_id" = 'tenant_id' AND "people"."id" NOT IN (
|
|
143
|
+
# SELECT "articles"."person_id" FROM "articles"
|
|
144
|
+
# WHERE "articles"."person_id" = "people"."id"
|
|
145
|
+
# AND "articles"."tenant_id" = 'tenant_id'
|
|
146
|
+
# AND "articles"."title" = 'Test' AND "articles"."published" = 't' AND ('default_scope' = 'default_scope')
|
|
147
|
+
# ) ORDER BY "people"."id" DESC
|
|
148
|
+
|
|
149
|
+
pending("spec should pass, but I do not know how/where to fix lib code")
|
|
150
|
+
s = Search.new(Person, published_articles_title_not_eq: 'Test')
|
|
151
|
+
expect(s.result.to_sql).to include 'default_scope'
|
|
152
|
+
expect(s.result.to_sql).to include 'published'
|
|
153
|
+
end
|
|
154
|
+
|
|
112
155
|
it 'discards empty conditions' do
|
|
113
156
|
s = Search.new(Person, children_name_eq: '')
|
|
114
157
|
condition = s.base[:children_name_eq]
|
|
@@ -220,6 +263,9 @@ module Ransack
|
|
|
220
263
|
let(:children_people_name_field) {
|
|
221
264
|
"#{quote_table_name("children_people")}.#{quote_column_name("name")}"
|
|
222
265
|
}
|
|
266
|
+
let(:notable_type_field) {
|
|
267
|
+
"#{quote_table_name("notes")}.#{quote_column_name("notable_type")}"
|
|
268
|
+
}
|
|
223
269
|
it 'evaluates conditions contextually' do
|
|
224
270
|
s = Search.new(Person, children_name_eq: 'Ernie')
|
|
225
271
|
expect(s.result).to be_an ActiveRecord::Relation
|
|
@@ -228,18 +274,22 @@ module Ransack
|
|
|
228
274
|
end
|
|
229
275
|
|
|
230
276
|
it 'use appropriate table alias' do
|
|
277
|
+
skip "Rails 6 regressed here, but it's fixed in 6-0-stable since https://github.com/rails/rails/commit/f9ba52477ca288e7effa5f6794ae3df3f4e982bc" if ENV["RAILS"] == "v6.0.3"
|
|
278
|
+
|
|
231
279
|
s = Search.new(Person, {
|
|
232
280
|
name_eq: "person_name_query",
|
|
233
281
|
articles_title_eq: "person_article_title_query",
|
|
234
282
|
parent_name_eq: "parent_name_query",
|
|
235
283
|
parent_articles_title_eq: 'parents_article_title_query'
|
|
236
284
|
}).result
|
|
285
|
+
|
|
237
286
|
real_query = remove_quotes_and_backticks(s.to_sql)
|
|
238
287
|
|
|
239
288
|
expect(real_query)
|
|
240
|
-
|
|
289
|
+
.to match(%r{LEFT OUTER JOIN articles ON (\('default_scope' = 'default_scope'\) AND )?articles.person_id = people.id})
|
|
241
290
|
expect(real_query)
|
|
242
|
-
|
|
291
|
+
.to match(%r{LEFT OUTER JOIN articles articles_people ON (\('default_scope' = 'default_scope'\) AND )?articles_people.person_id = parents_people.id})
|
|
292
|
+
|
|
243
293
|
expect(real_query)
|
|
244
294
|
.to include "people.name = 'person_name_query'"
|
|
245
295
|
expect(real_query)
|
|
@@ -282,6 +332,7 @@ module Ransack
|
|
|
282
332
|
s = Search.new(Note, notable_of_Person_type_name_eq: 'Ernie').result
|
|
283
333
|
expect(s).to be_an ActiveRecord::Relation
|
|
284
334
|
expect(s.to_sql).to match /#{people_name_field} = 'Ernie'/
|
|
335
|
+
expect(s.to_sql).to match /#{notable_type_field} = 'Person'/
|
|
285
336
|
end
|
|
286
337
|
|
|
287
338
|
it 'evaluates nested conditions' do
|
|
@@ -320,11 +371,8 @@ module Ransack
|
|
|
320
371
|
{ m: 'or', comments_body_cont: 'e', articles_comments_body_cont: 'e' }
|
|
321
372
|
]
|
|
322
373
|
)
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
else
|
|
326
|
-
all_or_load, uniq_or_distinct = :load, :distinct
|
|
327
|
-
end
|
|
374
|
+
|
|
375
|
+
all_or_load, uniq_or_distinct = :load, :distinct
|
|
328
376
|
expect(s.result.send(all_or_load).size)
|
|
329
377
|
.to eq(9000)
|
|
330
378
|
expect(s.result(distinct: true).size)
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/schema.rb
CHANGED
|
@@ -164,6 +164,8 @@ end
|
|
|
164
164
|
class Comment < ActiveRecord::Base
|
|
165
165
|
belongs_to :article
|
|
166
166
|
belongs_to :person
|
|
167
|
+
|
|
168
|
+
default_scope { where(disabled: false) }
|
|
167
169
|
end
|
|
168
170
|
|
|
169
171
|
class Tag < ActiveRecord::Base
|
|
@@ -209,6 +211,7 @@ module Schema
|
|
|
209
211
|
t.integer :article_id
|
|
210
212
|
t.integer :person_id
|
|
211
213
|
t.text :body
|
|
214
|
+
t.boolean :disabled, default: false
|
|
212
215
|
end
|
|
213
216
|
|
|
214
217
|
create_table :tags, force: true do |t|
|
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: 2.
|
|
4
|
+
version: 2.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ernie Miller
|
|
@@ -11,7 +11,7 @@ authors:
|
|
|
11
11
|
autorequire:
|
|
12
12
|
bindir: bin
|
|
13
13
|
cert_chain: []
|
|
14
|
-
date: 2020-
|
|
14
|
+
date: 2020-11-27 00:00:00.000000000 Z
|
|
15
15
|
dependencies:
|
|
16
16
|
- !ruby/object:Gem::Dependency
|
|
17
17
|
name: activerecord
|
|
@@ -19,28 +19,28 @@ dependencies:
|
|
|
19
19
|
requirements:
|
|
20
20
|
- - ">="
|
|
21
21
|
- !ruby/object:Gem::Version
|
|
22
|
-
version: 5.2.
|
|
22
|
+
version: 5.2.4
|
|
23
23
|
type: :runtime
|
|
24
24
|
prerelease: false
|
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
26
26
|
requirements:
|
|
27
27
|
- - ">="
|
|
28
28
|
- !ruby/object:Gem::Version
|
|
29
|
-
version: 5.2.
|
|
29
|
+
version: 5.2.4
|
|
30
30
|
- !ruby/object:Gem::Dependency
|
|
31
31
|
name: activesupport
|
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
|
33
33
|
requirements:
|
|
34
34
|
- - ">="
|
|
35
35
|
- !ruby/object:Gem::Version
|
|
36
|
-
version: 5.2.
|
|
36
|
+
version: 5.2.4
|
|
37
37
|
type: :runtime
|
|
38
38
|
prerelease: false
|
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
|
40
40
|
requirements:
|
|
41
41
|
- - ">="
|
|
42
42
|
- !ruby/object:Gem::Version
|
|
43
|
-
version: 5.2.
|
|
43
|
+
version: 5.2.4
|
|
44
44
|
- !ruby/object:Gem::Dependency
|
|
45
45
|
name: i18n
|
|
46
46
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -55,20 +55,6 @@ dependencies:
|
|
|
55
55
|
- - ">="
|
|
56
56
|
- !ruby/object:Gem::Version
|
|
57
57
|
version: '0'
|
|
58
|
-
- !ruby/object:Gem::Dependency
|
|
59
|
-
name: polyamorous
|
|
60
|
-
requirement: !ruby/object:Gem::Requirement
|
|
61
|
-
requirements:
|
|
62
|
-
- - '='
|
|
63
|
-
- !ruby/object:Gem::Version
|
|
64
|
-
version: 2.3.2
|
|
65
|
-
type: :runtime
|
|
66
|
-
prerelease: false
|
|
67
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
68
|
-
requirements:
|
|
69
|
-
- - '='
|
|
70
|
-
- !ruby/object:Gem::Version
|
|
71
|
-
version: 2.3.2
|
|
72
58
|
description: Ransack is the successor to the MetaSearch gem. It improves and expands
|
|
73
59
|
upon MetaSearch's functionality, but does not have a 100%-compatible API.
|
|
74
60
|
email:
|
|
@@ -88,6 +74,19 @@ files:
|
|
|
88
74
|
- LICENSE
|
|
89
75
|
- README.md
|
|
90
76
|
- Rakefile
|
|
77
|
+
- lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb
|
|
78
|
+
- lib/polyamorous/activerecord_5.2_ruby_2/join_dependency.rb
|
|
79
|
+
- lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb
|
|
80
|
+
- lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb
|
|
81
|
+
- lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb
|
|
82
|
+
- lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb
|
|
83
|
+
- lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb
|
|
84
|
+
- lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb
|
|
85
|
+
- lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb
|
|
86
|
+
- lib/polyamorous/join.rb
|
|
87
|
+
- lib/polyamorous/polyamorous.rb
|
|
88
|
+
- lib/polyamorous/swapping_reflection_class.rb
|
|
89
|
+
- lib/polyamorous/tree_node.rb
|
|
91
90
|
- lib/ransack.rb
|
|
92
91
|
- lib/ransack/adapters.rb
|
|
93
92
|
- lib/ransack/adapters/active_record.rb
|
|
@@ -150,21 +149,6 @@ files:
|
|
|
150
149
|
- logo/ransack-v.svg
|
|
151
150
|
- logo/ransack.png
|
|
152
151
|
- logo/ransack.svg
|
|
153
|
-
- polyamorous/lib/polyamorous.rb
|
|
154
|
-
- polyamorous/lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb
|
|
155
|
-
- polyamorous/lib/polyamorous/activerecord_5.2_ruby_2/join_dependency.rb
|
|
156
|
-
- polyamorous/lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb
|
|
157
|
-
- polyamorous/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb
|
|
158
|
-
- polyamorous/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb
|
|
159
|
-
- polyamorous/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb
|
|
160
|
-
- polyamorous/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb
|
|
161
|
-
- polyamorous/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb
|
|
162
|
-
- polyamorous/lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb
|
|
163
|
-
- polyamorous/lib/polyamorous/join.rb
|
|
164
|
-
- polyamorous/lib/polyamorous/swapping_reflection_class.rb
|
|
165
|
-
- polyamorous/lib/polyamorous/tree_node.rb
|
|
166
|
-
- polyamorous/lib/polyamorous/version.rb
|
|
167
|
-
- polyamorous/polyamorous.gemspec
|
|
168
152
|
- ransack.gemspec
|
|
169
153
|
- spec/blueprints/articles.rb
|
|
170
154
|
- spec/blueprints/comments.rb
|
|
@@ -174,14 +158,14 @@ files:
|
|
|
174
158
|
- spec/console.rb
|
|
175
159
|
- spec/helpers/polyamorous_helper.rb
|
|
176
160
|
- spec/helpers/ransack_helper.rb
|
|
161
|
+
- spec/polyamorous/join_association_spec.rb
|
|
162
|
+
- spec/polyamorous/join_dependency_spec.rb
|
|
163
|
+
- spec/polyamorous/join_spec.rb
|
|
177
164
|
- spec/ransack/adapters/active_record/base_spec.rb
|
|
178
165
|
- spec/ransack/adapters/active_record/context_spec.rb
|
|
179
166
|
- spec/ransack/configuration_spec.rb
|
|
180
167
|
- spec/ransack/helpers/form_builder_spec.rb
|
|
181
168
|
- spec/ransack/helpers/form_helper_spec.rb
|
|
182
|
-
- spec/ransack/join_association_spec.rb
|
|
183
|
-
- spec/ransack/join_dependency_spec.rb
|
|
184
|
-
- spec/ransack/join_spec.rb
|
|
185
169
|
- spec/ransack/nodes/condition_spec.rb
|
|
186
170
|
- spec/ransack/nodes/grouping_spec.rb
|
|
187
171
|
- spec/ransack/predicate_spec.rb
|
|
@@ -222,14 +206,14 @@ test_files:
|
|
|
222
206
|
- spec/console.rb
|
|
223
207
|
- spec/helpers/polyamorous_helper.rb
|
|
224
208
|
- spec/helpers/ransack_helper.rb
|
|
209
|
+
- spec/polyamorous/join_association_spec.rb
|
|
210
|
+
- spec/polyamorous/join_dependency_spec.rb
|
|
211
|
+
- spec/polyamorous/join_spec.rb
|
|
225
212
|
- spec/ransack/adapters/active_record/base_spec.rb
|
|
226
213
|
- spec/ransack/adapters/active_record/context_spec.rb
|
|
227
214
|
- spec/ransack/configuration_spec.rb
|
|
228
215
|
- spec/ransack/helpers/form_builder_spec.rb
|
|
229
216
|
- spec/ransack/helpers/form_helper_spec.rb
|
|
230
|
-
- spec/ransack/join_association_spec.rb
|
|
231
|
-
- spec/ransack/join_dependency_spec.rb
|
|
232
|
-
- spec/ransack/join_spec.rb
|
|
233
217
|
- spec/ransack/nodes/condition_spec.rb
|
|
234
218
|
- spec/ransack/nodes/grouping_spec.rb
|
|
235
219
|
- spec/ransack/predicate_spec.rb
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
module Polyamorous
|
|
2
|
-
module ReflectionExtensions
|
|
3
|
-
def build_join_constraint(table, foreign_table)
|
|
4
|
-
if polymorphic?
|
|
5
|
-
super(table, foreign_table)
|
|
6
|
-
.and(foreign_table[foreign_type].eq(klass.name))
|
|
7
|
-
else
|
|
8
|
-
super(table, foreign_table)
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
|
3
|
-
require "polyamorous/version"
|
|
4
|
-
|
|
5
|
-
Gem::Specification.new do |s|
|
|
6
|
-
s.name = "polyamorous"
|
|
7
|
-
s.version = Polyamorous::VERSION
|
|
8
|
-
s.authors = ["Ernie Miller", "Ryan Bigg", "Jon Atack", "Xiang Li"]
|
|
9
|
-
s.email = ["ernie@erniemiller.org", "radarlistener@gmail.com", "jonnyatack@gmail.com", "bigxiang@gmail.com"]
|
|
10
|
-
s.homepage = "https://github.com/activerecord-hackery/ransack/tree/master/polyamorous"
|
|
11
|
-
s.license = "MIT"
|
|
12
|
-
s.summary = %q{
|
|
13
|
-
Loves/is loved by polymorphic belongs_to associations, Ransack, Squeel, MetaSearch...
|
|
14
|
-
}
|
|
15
|
-
s.description = %q{
|
|
16
|
-
This is just an extraction from Ransack/Squeel. You probably don't want to use this
|
|
17
|
-
directly. It extends ActiveRecord's associations to support polymorphic belongs_to
|
|
18
|
-
associations.
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
s.add_dependency 'activerecord', '>= 5.2.1'
|
|
22
|
-
|
|
23
|
-
s.files = `git ls-files`.split("\n")
|
|
24
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
25
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
26
|
-
s.require_paths = ["lib"]
|
|
27
|
-
end
|