ransack 2.1.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +32 -22
- data/CHANGELOG.md +60 -1
- data/CONTRIBUTING.md +11 -6
- data/Gemfile +21 -17
- data/README.md +56 -29
- data/lib/polyamorous/{activerecord_5.2.1_ruby_2 → activerecord_5.2_ruby_2}/join_association.rb +2 -9
- data/lib/polyamorous/{activerecord_5.2.1_ruby_2 → activerecord_5.2_ruby_2}/join_dependency.rb +25 -3
- data/lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb +11 -0
- data/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +1 -0
- data/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +80 -0
- data/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +1 -0
- 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/lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb +1 -0
- data/lib/{polyamorous.rb → polyamorous/polyamorous.rb} +3 -3
- data/lib/ransack.rb +2 -2
- data/lib/ransack/adapters/active_record/base.rb +1 -0
- data/lib/ransack/adapters/active_record/context.rb +60 -68
- data/lib/ransack/adapters/active_record/ransack/constants.rb +17 -2
- data/lib/ransack/adapters/active_record/ransack/context.rb +2 -6
- data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +12 -5
- data/lib/ransack/adapters/active_record/ransack/translate.rb +1 -1
- data/lib/ransack/constants.rb +2 -3
- data/lib/ransack/context.rb +19 -18
- data/lib/ransack/helpers/form_builder.rb +5 -11
- data/lib/ransack/helpers/form_helper.rb +1 -1
- data/lib/ransack/locale/ar.yml +70 -0
- data/lib/ransack/locale/az.yml +1 -1
- data/lib/ransack/locale/ca.yml +70 -0
- data/lib/ransack/locale/es.yml +22 -22
- data/lib/ransack/locale/fa.yml +70 -0
- data/lib/ransack/locale/fi.yml +71 -0
- data/lib/ransack/locale/sk.yml +70 -0
- data/lib/ransack/locale/zh-CN.yml +12 -12
- data/lib/ransack/nodes/condition.rb +8 -0
- data/lib/ransack/nodes/grouping.rb +1 -1
- data/lib/ransack/predicate.rb +2 -1
- data/lib/ransack/search.rb +1 -0
- data/lib/ransack/translate.rb +115 -115
- data/lib/ransack/version.rb +1 -1
- data/ransack.gemspec +5 -21
- data/spec/helpers/polyamorous_helper.rb +3 -8
- data/spec/{ransack → polyamorous}/join_association_spec.rb +7 -0
- data/spec/{ransack → polyamorous}/join_dependency_spec.rb +18 -7
- data/spec/{ransack → polyamorous}/join_spec.rb +0 -0
- data/spec/ransack/adapters/active_record/base_spec.rb +8 -8
- data/spec/ransack/adapters/active_record/context_spec.rb +60 -17
- data/spec/ransack/helpers/form_helper_spec.rb +51 -51
- data/spec/ransack/predicate_spec.rb +54 -2
- data/spec/ransack/search_spec.rb +78 -13
- data/spec/spec_helper.rb +4 -0
- data/spec/support/schema.rb +13 -2
- metadata +29 -136
- data/lib/polyamorous/activerecord_5.0_ruby_2/join_association.rb +0 -2
- data/lib/polyamorous/activerecord_5.0_ruby_2/join_dependency.rb +0 -2
- data/lib/polyamorous/activerecord_5.1_ruby_2/join_association.rb +0 -32
- data/lib/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb +0 -112
- data/lib/polyamorous/activerecord_5.2.0_ruby_2/join_association.rb +0 -32
- data/lib/polyamorous/activerecord_5.2.0_ruby_2/join_dependency.rb +0 -113
@@ -1,32 +0,0 @@
|
|
1
|
-
# active_record_5.1_ruby_2/join_association.rb
|
2
|
-
|
3
|
-
module Polyamorous
|
4
|
-
module JoinAssociationExtensions
|
5
|
-
include SwappingReflectionClass
|
6
|
-
def self.prepended(base)
|
7
|
-
base.class_eval { attr_reader :join_type }
|
8
|
-
end
|
9
|
-
|
10
|
-
def initialize(reflection, children, polymorphic_class = nil,
|
11
|
-
join_type = Arel::Nodes::InnerJoin)
|
12
|
-
@join_type = join_type
|
13
|
-
if polymorphic_class && ::ActiveRecord::Base > polymorphic_class
|
14
|
-
swapping_reflection_klass(reflection, polymorphic_class) do |reflection|
|
15
|
-
super(reflection, children)
|
16
|
-
self.reflection.options[:polymorphic] = true
|
17
|
-
end
|
18
|
-
else
|
19
|
-
super(reflection, children)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def build_constraint(klass, table, key, foreign_table, foreign_key)
|
24
|
-
if reflection.polymorphic?
|
25
|
-
super(klass, table, key, foreign_table, foreign_key)
|
26
|
-
.and(foreign_table[reflection.foreign_type].eq(reflection.klass.name))
|
27
|
-
else
|
28
|
-
super(klass, table, key, foreign_table, foreign_key)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,112 +0,0 @@
|
|
1
|
-
# active_record_5.1_ruby_2/join_dependency.rb
|
2
|
-
|
3
|
-
module Polyamorous
|
4
|
-
module JoinDependencyExtensions
|
5
|
-
# Replaces ActiveRecord::Associations::JoinDependency#build
|
6
|
-
#
|
7
|
-
def build(associations, base_klass)
|
8
|
-
associations.map do |name, right|
|
9
|
-
if name.is_a? Join
|
10
|
-
reflection = find_reflection base_klass, name.name
|
11
|
-
reflection.check_validity!
|
12
|
-
reflection.check_eager_loadable!
|
13
|
-
|
14
|
-
klass = if reflection.polymorphic?
|
15
|
-
name.klass || base_klass
|
16
|
-
else
|
17
|
-
reflection.klass
|
18
|
-
end
|
19
|
-
JoinAssociation.new(reflection, build(right, klass), name.klass, name.type)
|
20
|
-
else
|
21
|
-
reflection = find_reflection base_klass, name
|
22
|
-
reflection.check_validity!
|
23
|
-
reflection.check_eager_loadable!
|
24
|
-
|
25
|
-
if reflection.polymorphic?
|
26
|
-
raise ActiveRecord::EagerLoadPolymorphicError.new(reflection)
|
27
|
-
end
|
28
|
-
JoinAssociation.new reflection, build(right, reflection.klass)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# Replaces ActiveRecord::Associations::JoinDependency#join_constraints
|
34
|
-
#
|
35
|
-
# This internal method was changed in Rails 5.0 by commit
|
36
|
-
# https://github.com/rails/rails/commit/e038975 which added
|
37
|
-
# left_outer_joins (see #make_polyamorous_left_outer_joins below) and added
|
38
|
-
# passing an additional argument, `join_type`, to #join_constraints.
|
39
|
-
#
|
40
|
-
def join_constraints(outer_joins, join_type)
|
41
|
-
joins = join_root.children.flat_map { |child|
|
42
|
-
if join_type == Arel::Nodes::OuterJoin
|
43
|
-
make_polyamorous_left_outer_joins join_root, child
|
44
|
-
else
|
45
|
-
make_polyamorous_inner_joins join_root, child
|
46
|
-
end
|
47
|
-
}
|
48
|
-
|
49
|
-
joins.concat outer_joins.flat_map { |oj|
|
50
|
-
if join_root.match? oj.join_root
|
51
|
-
walk(join_root, oj.join_root)
|
52
|
-
else
|
53
|
-
oj.join_root.children.flat_map { |child|
|
54
|
-
make_outer_joins(oj.join_root, child)
|
55
|
-
}
|
56
|
-
end
|
57
|
-
}
|
58
|
-
end
|
59
|
-
|
60
|
-
# Replaces ActiveRecord::Associations::JoinDependency#make_left_outer_joins,
|
61
|
-
# a new method that was added in Rails 5.0 with the following commit:
|
62
|
-
# https://github.com/rails/rails/commit/e038975
|
63
|
-
#
|
64
|
-
def make_polyamorous_left_outer_joins(parent, child)
|
65
|
-
tables = child.tables
|
66
|
-
join_type = Arel::Nodes::OuterJoin
|
67
|
-
info = make_constraints parent, child, tables, join_type
|
68
|
-
|
69
|
-
[info] + child.children.flat_map { |c|
|
70
|
-
make_polyamorous_left_outer_joins(child, c)
|
71
|
-
}
|
72
|
-
end
|
73
|
-
|
74
|
-
# Replaces ActiveRecord::Associations::JoinDependency#make_inner_joins
|
75
|
-
#
|
76
|
-
def make_polyamorous_inner_joins(parent, child)
|
77
|
-
tables = child.tables
|
78
|
-
join_type = child.join_type || Arel::Nodes::InnerJoin
|
79
|
-
info = make_constraints parent, child, tables, join_type
|
80
|
-
|
81
|
-
[info] + child.children.flat_map { |c|
|
82
|
-
make_polyamorous_inner_joins(child, c)
|
83
|
-
}
|
84
|
-
end
|
85
|
-
|
86
|
-
private :make_polyamorous_inner_joins, :make_polyamorous_left_outer_joins
|
87
|
-
|
88
|
-
module ClassMethods
|
89
|
-
# Prepended before ActiveRecord::Associations::JoinDependency#walk_tree
|
90
|
-
#
|
91
|
-
def walk_tree(associations, hash)
|
92
|
-
case associations
|
93
|
-
when TreeNode
|
94
|
-
associations.add_to_tree(hash)
|
95
|
-
when Hash
|
96
|
-
associations.each do |k, v|
|
97
|
-
cache =
|
98
|
-
if TreeNode === k
|
99
|
-
k.add_to_tree(hash)
|
100
|
-
else
|
101
|
-
hash[k] ||= {}
|
102
|
-
end
|
103
|
-
walk_tree(v, cache)
|
104
|
-
end
|
105
|
-
else
|
106
|
-
super(associations, hash)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
112
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# active_record_5.2_ruby_2/join_association.rb
|
2
|
-
|
3
|
-
module Polyamorous
|
4
|
-
module JoinAssociationExtensions
|
5
|
-
include SwappingReflectionClass
|
6
|
-
def self.prepended(base)
|
7
|
-
base.class_eval { attr_reader :join_type }
|
8
|
-
end
|
9
|
-
|
10
|
-
def initialize(reflection, children, alias_tracker, polymorphic_class = nil,
|
11
|
-
join_type = Arel::Nodes::InnerJoin)
|
12
|
-
@join_type = join_type
|
13
|
-
if polymorphic_class && ::ActiveRecord::Base > polymorphic_class
|
14
|
-
swapping_reflection_klass(reflection, polymorphic_class) do |reflection|
|
15
|
-
super(reflection, children, alias_tracker)
|
16
|
-
self.reflection.options[:polymorphic] = true
|
17
|
-
end
|
18
|
-
else
|
19
|
-
super(reflection, children, alias_tracker)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def build_constraint(klass, table, key, foreign_table, foreign_key)
|
24
|
-
if reflection.polymorphic?
|
25
|
-
super(klass, table, key, foreign_table, foreign_key)
|
26
|
-
.and(foreign_table[reflection.foreign_type].eq(reflection.klass.name))
|
27
|
-
else
|
28
|
-
super(klass, table, key, foreign_table, foreign_key)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,113 +0,0 @@
|
|
1
|
-
# active_record_5.2_ruby_2/join_dependency.rb
|
2
|
-
|
3
|
-
module Polyamorous
|
4
|
-
module JoinDependencyExtensions
|
5
|
-
# Replaces ActiveRecord::Associations::JoinDependency#build
|
6
|
-
#
|
7
|
-
def build(associations, base_klass)
|
8
|
-
associations.map do |name, right|
|
9
|
-
if name.is_a? Join
|
10
|
-
reflection = find_reflection base_klass, name.name
|
11
|
-
reflection.check_validity!
|
12
|
-
reflection.check_eager_loadable!
|
13
|
-
|
14
|
-
klass = if reflection.polymorphic?
|
15
|
-
name.klass || base_klass
|
16
|
-
else
|
17
|
-
reflection.klass
|
18
|
-
end
|
19
|
-
JoinAssociation.new(reflection, build(right, klass), alias_tracker, name.klass, name.type)
|
20
|
-
else
|
21
|
-
reflection = find_reflection base_klass, name
|
22
|
-
reflection.check_validity!
|
23
|
-
reflection.check_eager_loadable!
|
24
|
-
|
25
|
-
if reflection.polymorphic?
|
26
|
-
raise ActiveRecord::EagerLoadPolymorphicError.new(reflection)
|
27
|
-
end
|
28
|
-
JoinAssociation.new(reflection, build(right, reflection.klass), alias_tracker)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# Replaces ActiveRecord::Associations::JoinDependency#join_constraints
|
34
|
-
#
|
35
|
-
# This internal method was changed in Rails 5.0 by commit
|
36
|
-
# https://github.com/rails/rails/commit/e038975 which added
|
37
|
-
# left_outer_joins (see #make_polyamorous_left_outer_joins below) and added
|
38
|
-
# passing an additional argument, `join_type`, to #join_constraints.
|
39
|
-
#
|
40
|
-
def join_constraints(outer_joins, join_type)
|
41
|
-
@alias_tracker = alias_tracker
|
42
|
-
joins = join_root.children.flat_map { |child|
|
43
|
-
if join_type == Arel::Nodes::OuterJoin
|
44
|
-
make_polyamorous_left_outer_joins join_root, child
|
45
|
-
else
|
46
|
-
make_polyamorous_inner_joins join_root, child
|
47
|
-
end
|
48
|
-
}
|
49
|
-
|
50
|
-
joins.concat outer_joins.flat_map { |oj|
|
51
|
-
if join_root.match? oj.join_root
|
52
|
-
walk(join_root, oj.join_root)
|
53
|
-
else
|
54
|
-
oj.join_root.children.flat_map { |child|
|
55
|
-
make_outer_joins(oj.join_root, child)
|
56
|
-
}
|
57
|
-
end
|
58
|
-
}
|
59
|
-
end
|
60
|
-
|
61
|
-
# Replaces ActiveRecord::Associations::JoinDependency#make_left_outer_joins,
|
62
|
-
# a new method that was added in Rails 5.0 with the following commit:
|
63
|
-
# https://github.com/rails/rails/commit/e038975
|
64
|
-
#
|
65
|
-
def make_polyamorous_left_outer_joins(parent, child)
|
66
|
-
tables = child.tables
|
67
|
-
join_type = Arel::Nodes::OuterJoin
|
68
|
-
info = make_constraints parent, child, tables, join_type
|
69
|
-
|
70
|
-
info + child.children.flat_map { |c|
|
71
|
-
make_polyamorous_left_outer_joins(child, c)
|
72
|
-
}
|
73
|
-
end
|
74
|
-
|
75
|
-
# Replaces ActiveRecord::Associations::JoinDependency#make_inner_joins
|
76
|
-
#
|
77
|
-
def make_polyamorous_inner_joins(parent, child)
|
78
|
-
tables = child.tables
|
79
|
-
join_type = child.join_type || Arel::Nodes::InnerJoin
|
80
|
-
info = make_constraints parent, child, tables, join_type
|
81
|
-
|
82
|
-
info + child.children.flat_map { |c|
|
83
|
-
make_polyamorous_inner_joins(child, c)
|
84
|
-
}
|
85
|
-
end
|
86
|
-
|
87
|
-
private :make_polyamorous_inner_joins, :make_polyamorous_left_outer_joins
|
88
|
-
|
89
|
-
module ClassMethods
|
90
|
-
# Prepended before ActiveRecord::Associations::JoinDependency#walk_tree
|
91
|
-
#
|
92
|
-
def walk_tree(associations, hash)
|
93
|
-
case associations
|
94
|
-
when TreeNode
|
95
|
-
associations.add_to_tree(hash)
|
96
|
-
when Hash
|
97
|
-
associations.each do |k, v|
|
98
|
-
cache =
|
99
|
-
if TreeNode === k
|
100
|
-
k.add_to_tree(hash)
|
101
|
-
else
|
102
|
-
hash[k] ||= {}
|
103
|
-
end
|
104
|
-
walk_tree(v, cache)
|
105
|
-
end
|
106
|
-
else
|
107
|
-
super(associations, hash)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
end
|
113
|
-
end
|