ransack 2.1.1 → 2.5.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.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +3 -0
  3. data/.github/SECURITY.md +12 -0
  4. data/.github/workflows/cronjob.yml +102 -0
  5. data/.github/workflows/rubocop.yml +20 -0
  6. data/.github/workflows/test.yml +163 -0
  7. data/.gitignore +1 -0
  8. data/.rubocop.yml +44 -0
  9. data/CHANGELOG.md +64 -1
  10. data/CONTRIBUTING.md +16 -11
  11. data/Gemfile +23 -17
  12. data/README.md +190 -57
  13. data/bug_report_templates/test-ransack-scope-and-column-same-name.rb +78 -0
  14. data/bug_report_templates/test-ransacker-arel-present-predicate.rb +71 -0
  15. data/docs/img/create_release.png +0 -0
  16. data/docs/release_process.md +17 -0
  17. data/lib/polyamorous/{activerecord_5.2.1_ruby_2 → activerecord_5.2_ruby_2}/join_association.rb +2 -9
  18. data/lib/polyamorous/{activerecord_5.2.1_ruby_2 → activerecord_5.2_ruby_2}/join_dependency.rb +25 -3
  19. data/lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb +11 -0
  20. data/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +1 -0
  21. data/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +80 -0
  22. data/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +1 -0
  23. data/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +74 -0
  24. data/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +93 -0
  25. data/lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb +1 -0
  26. data/lib/polyamorous/activerecord_7.0_ruby_2/join_association.rb +1 -0
  27. data/lib/polyamorous/activerecord_7.0_ruby_2/join_dependency.rb +1 -0
  28. data/lib/polyamorous/activerecord_7.0_ruby_2/reflection.rb +1 -0
  29. data/lib/polyamorous/polyamorous.rb +24 -0
  30. data/lib/polyamorous.rb +1 -25
  31. data/lib/ransack/adapters/active_record/base.rb +5 -1
  32. data/lib/ransack/adapters/active_record/context.rb +71 -68
  33. data/lib/ransack/adapters/active_record/ransack/constants.rb +18 -3
  34. data/lib/ransack/adapters/active_record/ransack/context.rb +2 -6
  35. data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +13 -5
  36. data/lib/ransack/adapters/active_record/ransack/translate.rb +1 -1
  37. data/lib/ransack/configuration.rb +31 -1
  38. data/lib/ransack/constants.rb +3 -5
  39. data/lib/ransack/context.rb +19 -18
  40. data/lib/ransack/helpers/form_builder.rb +8 -14
  41. data/lib/ransack/helpers/form_helper.rb +1 -1
  42. data/lib/ransack/helpers.rb +1 -1
  43. data/lib/ransack/locale/az.yml +1 -1
  44. data/lib/ransack/locale/ca.yml +70 -0
  45. data/lib/ransack/locale/es.yml +22 -22
  46. data/lib/ransack/locale/fa.yml +70 -0
  47. data/lib/ransack/locale/fi.yml +71 -0
  48. data/lib/ransack/locale/sk.yml +70 -0
  49. data/lib/ransack/locale/sv.yml +70 -0
  50. data/lib/ransack/nodes/attribute.rb +1 -1
  51. data/lib/ransack/nodes/condition.rb +7 -1
  52. data/lib/ransack/nodes/grouping.rb +1 -1
  53. data/lib/ransack/nodes/sort.rb +3 -3
  54. data/lib/ransack/nodes/value.rb +1 -1
  55. data/lib/ransack/predicate.rb +2 -1
  56. data/lib/ransack/search.rb +4 -1
  57. data/lib/ransack/translate.rb +115 -115
  58. data/lib/ransack/version.rb +1 -1
  59. data/lib/ransack.rb +3 -3
  60. data/ransack.gemspec +8 -23
  61. data/spec/blueprints/articles.rb +1 -1
  62. data/spec/blueprints/comments.rb +1 -1
  63. data/spec/blueprints/notes.rb +1 -1
  64. data/spec/blueprints/tags.rb +1 -1
  65. data/spec/console.rb +5 -5
  66. data/spec/helpers/polyamorous_helper.rb +3 -8
  67. data/spec/helpers/ransack_helper.rb +1 -1
  68. data/spec/{ransack → polyamorous}/join_association_spec.rb +8 -1
  69. data/spec/{ransack → polyamorous}/join_dependency_spec.rb +18 -7
  70. data/spec/{ransack → polyamorous}/join_spec.rb +0 -0
  71. data/spec/ransack/adapters/active_record/base_spec.rb +26 -15
  72. data/spec/ransack/adapters/active_record/context_spec.rb +60 -18
  73. data/spec/ransack/configuration_spec.rb +24 -0
  74. data/spec/ransack/helpers/form_helper_spec.rb +16 -16
  75. data/spec/ransack/nodes/condition_spec.rb +13 -0
  76. data/spec/ransack/nodes/grouping_spec.rb +2 -2
  77. data/spec/ransack/predicate_spec.rb +54 -2
  78. data/spec/ransack/search_spec.rb +238 -36
  79. data/spec/spec_helper.rb +10 -5
  80. data/spec/support/schema.rb +37 -3
  81. metadata +45 -139
  82. data/.travis.yml +0 -37
  83. data/lib/polyamorous/activerecord_5.0_ruby_2/join_association.rb +0 -2
  84. data/lib/polyamorous/activerecord_5.0_ruby_2/join_dependency.rb +0 -2
  85. data/lib/polyamorous/activerecord_5.1_ruby_2/join_association.rb +0 -32
  86. data/lib/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb +0 -112
  87. data/lib/polyamorous/activerecord_5.2.0_ruby_2/join_association.rb +0 -32
  88. data/lib/polyamorous/activerecord_5.2.0_ruby_2/join_dependency.rb +0 -113
metadata CHANGED
@@ -1,60 +1,46 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ransack
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernie Miller
8
8
  - Ryan Bigg
9
9
  - Jon Atack
10
10
  - Sean Carroll
11
- autorequire:
11
+ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2018-12-05 00:00:00.000000000 Z
14
+ date: 2021-12-25 00:00:00.000000000 Z
15
15
  dependencies:
16
- - !ruby/object:Gem::Dependency
17
- name: actionpack
18
- requirement: !ruby/object:Gem::Requirement
19
- requirements:
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: '5.0'
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- version: '5.0'
30
16
  - !ruby/object:Gem::Dependency
31
17
  name: activerecord
32
18
  requirement: !ruby/object:Gem::Requirement
33
19
  requirements:
34
20
  - - ">="
35
21
  - !ruby/object:Gem::Version
36
- version: '5.0'
22
+ version: 5.2.4
37
23
  type: :runtime
38
24
  prerelease: false
39
25
  version_requirements: !ruby/object:Gem::Requirement
40
26
  requirements:
41
27
  - - ">="
42
28
  - !ruby/object:Gem::Version
43
- version: '5.0'
29
+ version: 5.2.4
44
30
  - !ruby/object:Gem::Dependency
45
31
  name: activesupport
46
32
  requirement: !ruby/object:Gem::Requirement
47
33
  requirements:
48
34
  - - ">="
49
35
  - !ruby/object:Gem::Version
50
- version: '5.0'
36
+ version: 5.2.4
51
37
  type: :runtime
52
38
  prerelease: false
53
39
  version_requirements: !ruby/object:Gem::Requirement
54
40
  requirements:
55
41
  - - ">="
56
42
  - !ruby/object:Gem::Version
57
- version: '5.0'
43
+ version: 5.2.4
58
44
  - !ruby/object:Gem::Dependency
59
45
  name: i18n
60
46
  requirement: !ruby/object:Gem::Requirement
@@ -69,104 +55,6 @@ dependencies:
69
55
  - - ">="
70
56
  - !ruby/object:Gem::Version
71
57
  version: '0'
72
- - !ruby/object:Gem::Dependency
73
- name: rspec
74
- requirement: !ruby/object:Gem::Requirement
75
- requirements:
76
- - - "~>"
77
- - !ruby/object:Gem::Version
78
- version: '3'
79
- type: :development
80
- prerelease: false
81
- version_requirements: !ruby/object:Gem::Requirement
82
- requirements:
83
- - - "~>"
84
- - !ruby/object:Gem::Version
85
- version: '3'
86
- - !ruby/object:Gem::Dependency
87
- name: machinist
88
- requirement: !ruby/object:Gem::Requirement
89
- requirements:
90
- - - "~>"
91
- - !ruby/object:Gem::Version
92
- version: 1.0.6
93
- type: :development
94
- prerelease: false
95
- version_requirements: !ruby/object:Gem::Requirement
96
- requirements:
97
- - - "~>"
98
- - !ruby/object:Gem::Version
99
- version: 1.0.6
100
- - !ruby/object:Gem::Dependency
101
- name: faker
102
- requirement: !ruby/object:Gem::Requirement
103
- requirements:
104
- - - "~>"
105
- - !ruby/object:Gem::Version
106
- version: 0.9.5
107
- type: :development
108
- prerelease: false
109
- version_requirements: !ruby/object:Gem::Requirement
110
- requirements:
111
- - - "~>"
112
- - !ruby/object:Gem::Version
113
- version: 0.9.5
114
- - !ruby/object:Gem::Dependency
115
- name: sqlite3
116
- requirement: !ruby/object:Gem::Requirement
117
- requirements:
118
- - - "~>"
119
- - !ruby/object:Gem::Version
120
- version: 1.3.3
121
- type: :development
122
- prerelease: false
123
- version_requirements: !ruby/object:Gem::Requirement
124
- requirements:
125
- - - "~>"
126
- - !ruby/object:Gem::Version
127
- version: 1.3.3
128
- - !ruby/object:Gem::Dependency
129
- name: pg
130
- requirement: !ruby/object:Gem::Requirement
131
- requirements:
132
- - - "~>"
133
- - !ruby/object:Gem::Version
134
- version: '0.21'
135
- type: :development
136
- prerelease: false
137
- version_requirements: !ruby/object:Gem::Requirement
138
- requirements:
139
- - - "~>"
140
- - !ruby/object:Gem::Version
141
- version: '0.21'
142
- - !ruby/object:Gem::Dependency
143
- name: mysql2
144
- requirement: !ruby/object:Gem::Requirement
145
- requirements:
146
- - - '='
147
- - !ruby/object:Gem::Version
148
- version: 0.3.20
149
- type: :development
150
- prerelease: false
151
- version_requirements: !ruby/object:Gem::Requirement
152
- requirements:
153
- - - '='
154
- - !ruby/object:Gem::Version
155
- version: 0.3.20
156
- - !ruby/object:Gem::Dependency
157
- name: pry
158
- requirement: !ruby/object:Gem::Requirement
159
- requirements:
160
- - - '='
161
- - !ruby/object:Gem::Version
162
- version: '0.10'
163
- type: :development
164
- prerelease: false
165
- version_requirements: !ruby/object:Gem::Requirement
166
- requirements:
167
- - - '='
168
- - !ruby/object:Gem::Version
169
- version: '0.10'
170
58
  description: Ransack is the successor to the MetaSearch gem. It improves and expands
171
59
  upon MetaSearch's functionality, but does not have a 100%-compatible API.
172
60
  email:
@@ -178,24 +66,38 @@ executables: []
178
66
  extensions: []
179
67
  extra_rdoc_files: []
180
68
  files:
69
+ - ".github/FUNDING.yml"
70
+ - ".github/SECURITY.md"
71
+ - ".github/workflows/cronjob.yml"
72
+ - ".github/workflows/rubocop.yml"
73
+ - ".github/workflows/test.yml"
181
74
  - ".gitignore"
182
- - ".travis.yml"
75
+ - ".rubocop.yml"
183
76
  - CHANGELOG.md
184
77
  - CONTRIBUTING.md
185
78
  - Gemfile
186
79
  - LICENSE
187
80
  - README.md
188
81
  - Rakefile
82
+ - bug_report_templates/test-ransack-scope-and-column-same-name.rb
83
+ - bug_report_templates/test-ransacker-arel-present-predicate.rb
84
+ - docs/img/create_release.png
85
+ - docs/release_process.md
189
86
  - lib/polyamorous.rb
190
- - lib/polyamorous/activerecord_5.0_ruby_2/join_association.rb
191
- - lib/polyamorous/activerecord_5.0_ruby_2/join_dependency.rb
192
- - lib/polyamorous/activerecord_5.1_ruby_2/join_association.rb
193
- - lib/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb
194
- - lib/polyamorous/activerecord_5.2.0_ruby_2/join_association.rb
195
- - lib/polyamorous/activerecord_5.2.0_ruby_2/join_dependency.rb
196
- - lib/polyamorous/activerecord_5.2.1_ruby_2/join_association.rb
197
- - lib/polyamorous/activerecord_5.2.1_ruby_2/join_dependency.rb
87
+ - lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb
88
+ - lib/polyamorous/activerecord_5.2_ruby_2/join_dependency.rb
89
+ - lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb
90
+ - lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb
91
+ - lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb
92
+ - lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb
93
+ - lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb
94
+ - lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb
95
+ - lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb
96
+ - lib/polyamorous/activerecord_7.0_ruby_2/join_association.rb
97
+ - lib/polyamorous/activerecord_7.0_ruby_2/join_dependency.rb
98
+ - lib/polyamorous/activerecord_7.0_ruby_2/reflection.rb
198
99
  - lib/polyamorous/join.rb
100
+ - lib/polyamorous/polyamorous.rb
199
101
  - lib/polyamorous/swapping_reflection_class.rb
200
102
  - lib/polyamorous/tree_node.rb
201
103
  - lib/ransack.rb
@@ -217,12 +119,15 @@ files:
217
119
  - lib/ransack/locale/ar.yml
218
120
  - lib/ransack/locale/az.yml
219
121
  - lib/ransack/locale/bg.yml
122
+ - lib/ransack/locale/ca.yml
220
123
  - lib/ransack/locale/cs.yml
221
124
  - lib/ransack/locale/da.yml
222
125
  - lib/ransack/locale/de.yml
223
126
  - lib/ransack/locale/el.yml
224
127
  - lib/ransack/locale/en.yml
225
128
  - lib/ransack/locale/es.yml
129
+ - lib/ransack/locale/fa.yml
130
+ - lib/ransack/locale/fi.yml
226
131
  - lib/ransack/locale/fr.yml
227
132
  - lib/ransack/locale/hu.yml
228
133
  - lib/ransack/locale/id.yml
@@ -232,6 +137,8 @@ files:
232
137
  - lib/ransack/locale/pt-BR.yml
233
138
  - lib/ransack/locale/ro.yml
234
139
  - lib/ransack/locale/ru.yml
140
+ - lib/ransack/locale/sk.yml
141
+ - lib/ransack/locale/sv.yml
235
142
  - lib/ransack/locale/tr.yml
236
143
  - lib/ransack/locale/zh-CN.yml
237
144
  - lib/ransack/locale/zh-TW.yml
@@ -265,14 +172,14 @@ files:
265
172
  - spec/console.rb
266
173
  - spec/helpers/polyamorous_helper.rb
267
174
  - spec/helpers/ransack_helper.rb
175
+ - spec/polyamorous/join_association_spec.rb
176
+ - spec/polyamorous/join_dependency_spec.rb
177
+ - spec/polyamorous/join_spec.rb
268
178
  - spec/ransack/adapters/active_record/base_spec.rb
269
179
  - spec/ransack/adapters/active_record/context_spec.rb
270
180
  - spec/ransack/configuration_spec.rb
271
181
  - spec/ransack/helpers/form_builder_spec.rb
272
182
  - spec/ransack/helpers/form_helper_spec.rb
273
- - spec/ransack/join_association_spec.rb
274
- - spec/ransack/join_dependency_spec.rb
275
- - spec/ransack/join_spec.rb
276
183
  - spec/ransack/nodes/condition_spec.rb
277
184
  - spec/ransack/nodes/grouping_spec.rb
278
185
  - spec/ransack/predicate_spec.rb
@@ -285,7 +192,7 @@ homepage: https://github.com/activerecord-hackery/ransack
285
192
  licenses:
286
193
  - MIT
287
194
  metadata: {}
288
- post_install_message:
195
+ post_install_message:
289
196
  rdoc_options: []
290
197
  require_paths:
291
198
  - lib
@@ -293,16 +200,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
293
200
  requirements:
294
201
  - - ">="
295
202
  - !ruby/object:Gem::Version
296
- version: '1.9'
203
+ version: '2.6'
297
204
  required_rubygems_version: !ruby/object:Gem::Requirement
298
205
  requirements:
299
206
  - - ">="
300
207
  - !ruby/object:Gem::Version
301
208
  version: '0'
302
209
  requirements: []
303
- rubyforge_project: ransack
304
- rubygems_version: 2.7.6
305
- signing_key:
210
+ rubygems_version: 3.1.4
211
+ signing_key:
306
212
  specification_version: 4
307
213
  summary: Object-based searching for Active Record and Mongoid (currently).
308
214
  test_files:
@@ -314,14 +220,14 @@ test_files:
314
220
  - spec/console.rb
315
221
  - spec/helpers/polyamorous_helper.rb
316
222
  - spec/helpers/ransack_helper.rb
223
+ - spec/polyamorous/join_association_spec.rb
224
+ - spec/polyamorous/join_dependency_spec.rb
225
+ - spec/polyamorous/join_spec.rb
317
226
  - spec/ransack/adapters/active_record/base_spec.rb
318
227
  - spec/ransack/adapters/active_record/context_spec.rb
319
228
  - spec/ransack/configuration_spec.rb
320
229
  - spec/ransack/helpers/form_builder_spec.rb
321
230
  - spec/ransack/helpers/form_helper_spec.rb
322
- - spec/ransack/join_association_spec.rb
323
- - spec/ransack/join_dependency_spec.rb
324
- - spec/ransack/join_spec.rb
325
231
  - spec/ransack/nodes/condition_spec.rb
326
232
  - spec/ransack/nodes/grouping_spec.rb
327
233
  - spec/ransack/predicate_spec.rb
data/.travis.yml DELETED
@@ -1,37 +0,0 @@
1
- language: ruby
2
-
3
- sudo: false
4
-
5
- rvm:
6
- - 2.5
7
-
8
- env:
9
- - RAILS=5-2-stable DB=sqlite3
10
- - RAILS=5-2-stable DB=mysql
11
- - RAILS=5-2-stable DB=postgres
12
-
13
- - RAILS=v5.2.1 DB=sqlite3
14
- - RAILS=v5.2.1 DB=mysql
15
- - RAILS=v5.2.1 DB=postgres
16
-
17
- - RAILS=v5.2.0 DB=sqlite3
18
- - RAILS=v5.2.0 DB=mysql
19
- - RAILS=v5.2.0 DB=postgres
20
-
21
- - RAILS=5-1-stable DB=sqlite3
22
- - RAILS=5-1-stable DB=mysql
23
- - RAILS=5-1-stable DB=postgres
24
-
25
- matrix:
26
- allow_failures:
27
- - env: RAILS=5-2-stable DB=sqlite3
28
- - env: RAILS=5-2-stable DB=mysql
29
- - env: RAILS=5-2-stable DB=postgres
30
- before_script:
31
- - mysql -e 'create database ransack collate utf8_general_ci;'
32
- - mysql -e 'use ransack;show variables like "%character%";show variables like "%collation%";'
33
- - psql -c 'create database ransack;' -U postgres
34
-
35
- addons:
36
- code_climate:
37
- repo_token: 8b701c4364d51a0217105e08c06922d600cec3d9e60d546a89e3ddfe46e0664e
@@ -1,2 +0,0 @@
1
- # active_record_5.0_ruby_2/join_association.rb
2
- require 'polyamorous/activerecord_5.1_ruby_2/join_association'
@@ -1,2 +0,0 @@
1
- # active_record_5.0_ruby_2/join_dependency.rb
2
- require 'polyamorous/activerecord_5.1_ruby_2/join_dependency'
@@ -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