ransack 2.4.2 → 4.0.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/codeql.yml +72 -0
- data/.github/workflows/cronjob.yml +6 -9
- data/.github/workflows/deploy.yml +35 -0
- data/.github/workflows/rubocop.yml +1 -1
- data/.github/workflows/test-deploy.yml +29 -0
- data/.github/workflows/test.yml +22 -48
- data/.nojekyll +0 -0
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +208 -11
- data/CONTRIBUTING.md +41 -18
- data/Gemfile +10 -10
- data/README.md +44 -977
- data/bug_report_templates/test-ransacker-arel-present-predicate.rb +4 -0
- data/docs/.gitignore +19 -0
- data/docs/.nojekyll +0 -0
- data/docs/babel.config.js +3 -0
- data/docs/blog/2022-03-27-ransack-3.0.0.md +20 -0
- data/docs/docs/getting-started/_category_.json +4 -0
- data/docs/docs/getting-started/advanced-mode.md +46 -0
- data/docs/docs/getting-started/configuration.md +47 -0
- data/docs/docs/getting-started/search-matches.md +67 -0
- data/docs/docs/getting-started/simple-mode.md +288 -0
- data/docs/docs/getting-started/sorting.md +79 -0
- data/docs/docs/getting-started/using-predicates.md +282 -0
- data/docs/docs/going-further/_category_.json +4 -0
- data/docs/docs/going-further/acts-as-taggable-on.md +114 -0
- data/docs/docs/going-further/associations.md +70 -0
- data/docs/docs/going-further/custom-predicates.md +52 -0
- data/docs/docs/going-further/documentation.md +43 -0
- data/docs/docs/going-further/exporting-to-csv.md +49 -0
- data/docs/docs/going-further/external-guides.md +57 -0
- data/docs/docs/going-further/form-customisation.md +63 -0
- data/docs/docs/going-further/i18n.md +53 -0
- data/docs/docs/going-further/merging-searches.md +41 -0
- data/docs/docs/going-further/other-notes.md +428 -0
- data/docs/docs/going-further/polymorphic-search.md +40 -0
- data/docs/docs/going-further/ransackers.md +331 -0
- data/docs/docs/going-further/release_process.md +36 -0
- data/docs/docs/going-further/saving-queries.md +82 -0
- data/docs/docs/going-further/searching-postgres.md +57 -0
- data/docs/docs/going-further/wiki-contributors.md +82 -0
- data/docs/docs/intro.md +99 -0
- data/docs/docusaurus.config.js +120 -0
- data/docs/package.json +42 -0
- data/docs/sidebars.js +31 -0
- data/docs/src/components/HomepageFeatures/index.js +64 -0
- data/docs/src/components/HomepageFeatures/styles.module.css +11 -0
- data/docs/src/css/custom.css +39 -0
- data/docs/src/pages/index.module.css +23 -0
- data/docs/src/pages/markdown-page.md +7 -0
- data/docs/static/.nojekyll +0 -0
- data/docs/static/img/docusaurus.png +0 -0
- data/docs/static/img/favicon.ico +0 -0
- data/docs/static/img/logo.svg +1 -0
- data/docs/static/img/tutorial/docsVersionDropdown.png +0 -0
- data/docs/static/img/tutorial/localeDropdown.png +0 -0
- data/docs/static/img/undraw_docusaurus_mountain.svg +171 -0
- data/docs/static/img/undraw_docusaurus_react.svg +170 -0
- data/docs/static/img/undraw_docusaurus_tree.svg +40 -0
- data/docs/yarn.lock +8790 -0
- data/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +0 -4
- data/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +0 -1
- data/lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb +11 -1
- data/lib/polyamorous/activerecord_7.1_ruby_2/join_association.rb +1 -0
- data/lib/polyamorous/activerecord_7.1_ruby_2/join_dependency.rb +1 -0
- data/lib/polyamorous/activerecord_7.1_ruby_2/reflection.rb +1 -0
- data/lib/ransack/adapters/active_record/base.rb +79 -10
- data/lib/ransack/adapters/active_record/context.rb +24 -51
- data/lib/ransack/configuration.rb +39 -12
- data/lib/ransack/constants.rb +125 -3
- data/lib/ransack/context.rb +34 -5
- data/lib/ransack/helpers/form_builder.rb +3 -3
- data/lib/ransack/helpers/form_helper.rb +14 -5
- data/lib/ransack/locale/sv.yml +70 -0
- data/lib/ransack/nodes/attribute.rb +2 -2
- data/lib/ransack/nodes/condition.rb +80 -7
- data/lib/ransack/nodes/grouping.rb +3 -3
- data/lib/ransack/nodes/node.rb +1 -1
- data/lib/ransack/nodes/sort.rb +2 -2
- data/lib/ransack/nodes/value.rb +2 -2
- data/lib/ransack/predicate.rb +1 -1
- data/lib/ransack/ransacker.rb +1 -1
- data/lib/ransack/search.rb +13 -7
- data/lib/ransack/translate.rb +3 -3
- data/lib/ransack/version.rb +1 -1
- data/lib/ransack/visitor.rb +38 -2
- data/lib/ransack.rb +3 -6
- data/ransack.gemspec +5 -5
- data/spec/helpers/polyamorous_helper.rb +2 -8
- data/spec/polyamorous/activerecord_compatibility_spec.rb +15 -0
- data/spec/polyamorous/join_association_spec.rb +1 -6
- data/spec/polyamorous/join_dependency_spec.rb +0 -16
- data/spec/ransack/adapters/active_record/base_spec.rb +101 -11
- data/spec/ransack/configuration_spec.rb +23 -9
- data/spec/ransack/helpers/form_builder_spec.rb +8 -8
- data/spec/ransack/helpers/form_helper_spec.rb +93 -4
- data/spec/ransack/nodes/condition_spec.rb +37 -0
- data/spec/ransack/nodes/value_spec.rb +115 -0
- data/spec/ransack/predicate_spec.rb +36 -1
- data/spec/ransack/search_spec.rb +140 -27
- data/spec/ransack/translate_spec.rb +1 -1
- data/spec/support/schema.rb +75 -9
- metadata +83 -37
- data/docs/release_process.md +0 -20
- data/lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb +0 -24
- data/lib/polyamorous/activerecord_5.2_ruby_2/join_dependency.rb +0 -79
- data/lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb +0 -11
- data/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +0 -1
- data/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +0 -80
- data/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +0 -1
- data/lib/ransack/adapters/active_record/ransack/constants.rb +0 -128
- data/lib/ransack/adapters/active_record/ransack/context.rb +0 -56
- data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +0 -68
- data/lib/ransack/adapters/active_record/ransack/translate.rb +0 -8
- data/lib/ransack/adapters/active_record/ransack/visitor.rb +0 -47
- data/lib/ransack/adapters.rb +0 -64
- data/lib/ransack/nodes.rb +0 -8
- /data/docs/{img → docs/going-further/img}/create_release.png +0 -0
- /data/{logo → docs/static/logo}/ransack-h.png +0 -0
- /data/{logo → docs/static/logo}/ransack-h.svg +0 -0
- /data/{logo → docs/static/logo}/ransack-v.png +0 -0
- /data/{logo → docs/static/logo}/ransack-v.svg +0 -0
- /data/{logo → docs/static/logo}/ransack.png +0 -0
- /data/{logo → docs/static/logo}/ransack.svg +0 -0
- /data/lib/polyamorous/{activerecord_6.2_ruby_2 → activerecord_7.0_ruby_2}/join_association.rb +0 -0
- /data/lib/polyamorous/{activerecord_6.2_ruby_2 → activerecord_7.0_ruby_2}/join_dependency.rb +0 -0
- /data/lib/polyamorous/{activerecord_6.2_ruby_2 → activerecord_7.0_ruby_2}/reflection.rb +0 -0
- /data/lib/ransack/{adapters/active_record.rb → active_record.rb} +0 -0
metadata
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ransack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.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
|
-
|
11
|
+
- David Rodríguez
|
12
|
+
autorequire:
|
12
13
|
bindir: bin
|
13
14
|
cert_chain: []
|
14
|
-
date:
|
15
|
+
date: 2023-02-09 00:00:00.000000000 Z
|
15
16
|
dependencies:
|
16
17
|
- !ruby/object:Gem::Dependency
|
17
18
|
name: activerecord
|
@@ -19,28 +20,28 @@ dependencies:
|
|
19
20
|
requirements:
|
20
21
|
- - ">="
|
21
22
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
23
|
+
version: 6.1.5
|
23
24
|
type: :runtime
|
24
25
|
prerelease: false
|
25
26
|
version_requirements: !ruby/object:Gem::Requirement
|
26
27
|
requirements:
|
27
28
|
- - ">="
|
28
29
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
30
|
+
version: 6.1.5
|
30
31
|
- !ruby/object:Gem::Dependency
|
31
32
|
name: activesupport
|
32
33
|
requirement: !ruby/object:Gem::Requirement
|
33
34
|
requirements:
|
34
35
|
- - ">="
|
35
36
|
- !ruby/object:Gem::Version
|
36
|
-
version:
|
37
|
+
version: 6.1.5
|
37
38
|
type: :runtime
|
38
39
|
prerelease: false
|
39
40
|
version_requirements: !ruby/object:Gem::Requirement
|
40
41
|
requirements:
|
41
42
|
- - ">="
|
42
43
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
44
|
+
version: 6.1.5
|
44
45
|
- !ruby/object:Gem::Dependency
|
45
46
|
name: i18n
|
46
47
|
requirement: !ruby/object:Gem::Requirement
|
@@ -68,10 +69,14 @@ extra_rdoc_files: []
|
|
68
69
|
files:
|
69
70
|
- ".github/FUNDING.yml"
|
70
71
|
- ".github/SECURITY.md"
|
72
|
+
- ".github/workflows/codeql.yml"
|
71
73
|
- ".github/workflows/cronjob.yml"
|
74
|
+
- ".github/workflows/deploy.yml"
|
72
75
|
- ".github/workflows/rubocop.yml"
|
76
|
+
- ".github/workflows/test-deploy.yml"
|
73
77
|
- ".github/workflows/test.yml"
|
74
78
|
- ".gitignore"
|
79
|
+
- ".nojekyll"
|
75
80
|
- ".rubocop.yml"
|
76
81
|
- CHANGELOG.md
|
77
82
|
- CONTRIBUTING.md
|
@@ -81,34 +86,77 @@ files:
|
|
81
86
|
- Rakefile
|
82
87
|
- bug_report_templates/test-ransack-scope-and-column-same-name.rb
|
83
88
|
- bug_report_templates/test-ransacker-arel-present-predicate.rb
|
84
|
-
- docs
|
85
|
-
- docs
|
86
|
-
-
|
87
|
-
-
|
88
|
-
-
|
89
|
-
-
|
90
|
-
-
|
91
|
-
-
|
89
|
+
- docs/.gitignore
|
90
|
+
- docs/.nojekyll
|
91
|
+
- docs/babel.config.js
|
92
|
+
- docs/blog/2022-03-27-ransack-3.0.0.md
|
93
|
+
- docs/docs/getting-started/_category_.json
|
94
|
+
- docs/docs/getting-started/advanced-mode.md
|
95
|
+
- docs/docs/getting-started/configuration.md
|
96
|
+
- docs/docs/getting-started/search-matches.md
|
97
|
+
- docs/docs/getting-started/simple-mode.md
|
98
|
+
- docs/docs/getting-started/sorting.md
|
99
|
+
- docs/docs/getting-started/using-predicates.md
|
100
|
+
- docs/docs/going-further/_category_.json
|
101
|
+
- docs/docs/going-further/acts-as-taggable-on.md
|
102
|
+
- docs/docs/going-further/associations.md
|
103
|
+
- docs/docs/going-further/custom-predicates.md
|
104
|
+
- docs/docs/going-further/documentation.md
|
105
|
+
- docs/docs/going-further/exporting-to-csv.md
|
106
|
+
- docs/docs/going-further/external-guides.md
|
107
|
+
- docs/docs/going-further/form-customisation.md
|
108
|
+
- docs/docs/going-further/i18n.md
|
109
|
+
- docs/docs/going-further/img/create_release.png
|
110
|
+
- docs/docs/going-further/merging-searches.md
|
111
|
+
- docs/docs/going-further/other-notes.md
|
112
|
+
- docs/docs/going-further/polymorphic-search.md
|
113
|
+
- docs/docs/going-further/ransackers.md
|
114
|
+
- docs/docs/going-further/release_process.md
|
115
|
+
- docs/docs/going-further/saving-queries.md
|
116
|
+
- docs/docs/going-further/searching-postgres.md
|
117
|
+
- docs/docs/going-further/wiki-contributors.md
|
118
|
+
- docs/docs/intro.md
|
119
|
+
- docs/docusaurus.config.js
|
120
|
+
- docs/package.json
|
121
|
+
- docs/sidebars.js
|
122
|
+
- docs/src/components/HomepageFeatures/index.js
|
123
|
+
- docs/src/components/HomepageFeatures/styles.module.css
|
124
|
+
- docs/src/css/custom.css
|
125
|
+
- docs/src/pages/index.module.css
|
126
|
+
- docs/src/pages/markdown-page.md
|
127
|
+
- docs/static/.nojekyll
|
128
|
+
- docs/static/img/docusaurus.png
|
129
|
+
- docs/static/img/favicon.ico
|
130
|
+
- docs/static/img/logo.svg
|
131
|
+
- docs/static/img/tutorial/docsVersionDropdown.png
|
132
|
+
- docs/static/img/tutorial/localeDropdown.png
|
133
|
+
- docs/static/img/undraw_docusaurus_mountain.svg
|
134
|
+
- docs/static/img/undraw_docusaurus_react.svg
|
135
|
+
- docs/static/img/undraw_docusaurus_tree.svg
|
136
|
+
- docs/static/logo/ransack-h.png
|
137
|
+
- docs/static/logo/ransack-h.svg
|
138
|
+
- docs/static/logo/ransack-v.png
|
139
|
+
- docs/static/logo/ransack-v.svg
|
140
|
+
- docs/static/logo/ransack.png
|
141
|
+
- docs/static/logo/ransack.svg
|
142
|
+
- docs/yarn.lock
|
92
143
|
- lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb
|
93
144
|
- lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb
|
94
145
|
- lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb
|
95
|
-
- lib/polyamorous/
|
96
|
-
- lib/polyamorous/
|
97
|
-
- lib/polyamorous/
|
146
|
+
- lib/polyamorous/activerecord_7.0_ruby_2/join_association.rb
|
147
|
+
- lib/polyamorous/activerecord_7.0_ruby_2/join_dependency.rb
|
148
|
+
- lib/polyamorous/activerecord_7.0_ruby_2/reflection.rb
|
149
|
+
- lib/polyamorous/activerecord_7.1_ruby_2/join_association.rb
|
150
|
+
- lib/polyamorous/activerecord_7.1_ruby_2/join_dependency.rb
|
151
|
+
- lib/polyamorous/activerecord_7.1_ruby_2/reflection.rb
|
98
152
|
- lib/polyamorous/join.rb
|
99
153
|
- lib/polyamorous/polyamorous.rb
|
100
154
|
- lib/polyamorous/swapping_reflection_class.rb
|
101
155
|
- lib/polyamorous/tree_node.rb
|
102
156
|
- lib/ransack.rb
|
103
|
-
- lib/ransack/
|
104
|
-
- lib/ransack/adapters/active_record.rb
|
157
|
+
- lib/ransack/active_record.rb
|
105
158
|
- lib/ransack/adapters/active_record/base.rb
|
106
159
|
- lib/ransack/adapters/active_record/context.rb
|
107
|
-
- lib/ransack/adapters/active_record/ransack/constants.rb
|
108
|
-
- lib/ransack/adapters/active_record/ransack/context.rb
|
109
|
-
- lib/ransack/adapters/active_record/ransack/nodes/condition.rb
|
110
|
-
- lib/ransack/adapters/active_record/ransack/translate.rb
|
111
|
-
- lib/ransack/adapters/active_record/ransack/visitor.rb
|
112
160
|
- lib/ransack/configuration.rb
|
113
161
|
- lib/ransack/constants.rb
|
114
162
|
- lib/ransack/context.rb
|
@@ -137,11 +185,11 @@ files:
|
|
137
185
|
- lib/ransack/locale/ro.yml
|
138
186
|
- lib/ransack/locale/ru.yml
|
139
187
|
- lib/ransack/locale/sk.yml
|
188
|
+
- lib/ransack/locale/sv.yml
|
140
189
|
- lib/ransack/locale/tr.yml
|
141
190
|
- lib/ransack/locale/zh-CN.yml
|
142
191
|
- lib/ransack/locale/zh-TW.yml
|
143
192
|
- lib/ransack/naming.rb
|
144
|
-
- lib/ransack/nodes.rb
|
145
193
|
- lib/ransack/nodes/attribute.rb
|
146
194
|
- lib/ransack/nodes/bindable.rb
|
147
195
|
- lib/ransack/nodes/condition.rb
|
@@ -155,12 +203,6 @@ files:
|
|
155
203
|
- lib/ransack/translate.rb
|
156
204
|
- lib/ransack/version.rb
|
157
205
|
- lib/ransack/visitor.rb
|
158
|
-
- logo/ransack-h.png
|
159
|
-
- logo/ransack-h.svg
|
160
|
-
- logo/ransack-v.png
|
161
|
-
- logo/ransack-v.svg
|
162
|
-
- logo/ransack.png
|
163
|
-
- logo/ransack.svg
|
164
206
|
- ransack.gemspec
|
165
207
|
- spec/blueprints/articles.rb
|
166
208
|
- spec/blueprints/comments.rb
|
@@ -170,6 +212,7 @@ files:
|
|
170
212
|
- spec/console.rb
|
171
213
|
- spec/helpers/polyamorous_helper.rb
|
172
214
|
- spec/helpers/ransack_helper.rb
|
215
|
+
- spec/polyamorous/activerecord_compatibility_spec.rb
|
173
216
|
- spec/polyamorous/join_association_spec.rb
|
174
217
|
- spec/polyamorous/join_dependency_spec.rb
|
175
218
|
- spec/polyamorous/join_spec.rb
|
@@ -180,6 +223,7 @@ files:
|
|
180
223
|
- spec/ransack/helpers/form_helper_spec.rb
|
181
224
|
- spec/ransack/nodes/condition_spec.rb
|
182
225
|
- spec/ransack/nodes/grouping_spec.rb
|
226
|
+
- spec/ransack/nodes/value_spec.rb
|
183
227
|
- spec/ransack/predicate_spec.rb
|
184
228
|
- spec/ransack/search_spec.rb
|
185
229
|
- spec/ransack/translate_spec.rb
|
@@ -190,7 +234,7 @@ homepage: https://github.com/activerecord-hackery/ransack
|
|
190
234
|
licenses:
|
191
235
|
- MIT
|
192
236
|
metadata: {}
|
193
|
-
post_install_message:
|
237
|
+
post_install_message:
|
194
238
|
rdoc_options: []
|
195
239
|
require_paths:
|
196
240
|
- lib
|
@@ -198,17 +242,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
198
242
|
requirements:
|
199
243
|
- - ">="
|
200
244
|
- !ruby/object:Gem::Version
|
201
|
-
version: '2.
|
245
|
+
version: '2.7'
|
202
246
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
203
247
|
requirements:
|
204
248
|
- - ">="
|
205
249
|
- !ruby/object:Gem::Version
|
206
250
|
version: '0'
|
207
251
|
requirements: []
|
208
|
-
rubygems_version: 3.
|
209
|
-
signing_key:
|
252
|
+
rubygems_version: 3.4.6
|
253
|
+
signing_key:
|
210
254
|
specification_version: 4
|
211
|
-
summary: Object-based searching for Active Record
|
255
|
+
summary: Object-based searching for Active Record.
|
212
256
|
test_files:
|
213
257
|
- spec/blueprints/articles.rb
|
214
258
|
- spec/blueprints/comments.rb
|
@@ -218,6 +262,7 @@ test_files:
|
|
218
262
|
- spec/console.rb
|
219
263
|
- spec/helpers/polyamorous_helper.rb
|
220
264
|
- spec/helpers/ransack_helper.rb
|
265
|
+
- spec/polyamorous/activerecord_compatibility_spec.rb
|
221
266
|
- spec/polyamorous/join_association_spec.rb
|
222
267
|
- spec/polyamorous/join_dependency_spec.rb
|
223
268
|
- spec/polyamorous/join_spec.rb
|
@@ -228,6 +273,7 @@ test_files:
|
|
228
273
|
- spec/ransack/helpers/form_helper_spec.rb
|
229
274
|
- spec/ransack/nodes/condition_spec.rb
|
230
275
|
- spec/ransack/nodes/grouping_spec.rb
|
276
|
+
- spec/ransack/nodes/value_spec.rb
|
231
277
|
- spec/ransack/predicate_spec.rb
|
232
278
|
- spec/ransack/search_spec.rb
|
233
279
|
- spec/ransack/translate_spec.rb
|
data/docs/release_process.md
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
## Release Process
|
2
|
-
|
3
|
-
*For maintainers of Ransack.*
|
4
|
-
|
5
|
-
To release a new version of Ransack and publish it to RubyGems, take the following steps:
|
6
|
-
|
7
|
-
- Create a new release, marked `Prerelease`.
|
8
|
-
<<<<<<< Updated upstream
|
9
|
-
- Update the versions file to the new release, commit and push to `master`.
|
10
|
-
=======
|
11
|
-
- Update the [version.rb](../lib/ransack/version.rb) file to the new release, commit and push to `master`.
|
12
|
-
>>>>>>> Stashed changes
|
13
|
-
- From the terminal, run the following commands
|
14
|
-
|
15
|
-
```bash
|
16
|
-
rake build
|
17
|
-
rake release
|
18
|
-
```
|
19
|
-
|
20
|
-
![Create a Release](img/create_release.png)
|
@@ -1,24 +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
|
-
|
20
|
-
def ==(other)
|
21
|
-
base_klass == other.base_klass
|
22
|
-
end
|
23
|
-
end
|
24
|
-
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, join_type, 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
|
40
|
-
else
|
41
|
-
make_join_constraints(oj.join_root, 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
|
@@ -1 +0,0 @@
|
|
1
|
-
require 'polyamorous/activerecord_5.2_ruby_2/join_association'
|
@@ -1,80 +0,0 @@
|
|
1
|
-
# active_record_6.0_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)
|
32
|
-
@alias_tracker = alias_tracker
|
33
|
-
|
34
|
-
construct_tables!(join_root)
|
35
|
-
joins = make_join_constraints(join_root, join_type)
|
36
|
-
|
37
|
-
joins.concat joins_to_add.flat_map { |oj|
|
38
|
-
construct_tables!(oj.join_root)
|
39
|
-
if join_root.match?(oj.join_root) && join_root.table.name == oj.join_root.table.name
|
40
|
-
walk join_root, oj.join_root, oj.join_type
|
41
|
-
else
|
42
|
-
make_join_constraints(oj.join_root, oj.join_type)
|
43
|
-
end
|
44
|
-
}
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
def make_constraints(parent, child, join_type = Arel::Nodes::OuterJoin)
|
49
|
-
foreign_table = parent.table
|
50
|
-
foreign_klass = parent.base_klass
|
51
|
-
join_type = child.join_type || join_type if join_type == Arel::Nodes::InnerJoin
|
52
|
-
joins = child.join_constraints(foreign_table, foreign_klass, join_type, alias_tracker)
|
53
|
-
joins.concat child.children.flat_map { |c| make_constraints(child, c, join_type) }
|
54
|
-
end
|
55
|
-
|
56
|
-
module ClassMethods
|
57
|
-
# Prepended before ActiveRecord::Associations::JoinDependency#walk_tree
|
58
|
-
#
|
59
|
-
def walk_tree(associations, hash)
|
60
|
-
case associations
|
61
|
-
when TreeNode
|
62
|
-
associations.add_to_tree(hash)
|
63
|
-
when Hash
|
64
|
-
associations.each do |k, v|
|
65
|
-
cache =
|
66
|
-
if TreeNode === k
|
67
|
-
k.add_to_tree(hash)
|
68
|
-
else
|
69
|
-
hash[k] ||= {}
|
70
|
-
end
|
71
|
-
walk_tree(v, cache)
|
72
|
-
end
|
73
|
-
else
|
74
|
-
super(associations, hash)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
require 'polyamorous/activerecord_5.2_ruby_2/reflection'
|
@@ -1,128 +0,0 @@
|
|
1
|
-
module Ransack
|
2
|
-
module Constants
|
3
|
-
DISTINCT = 'DISTINCT '.freeze
|
4
|
-
|
5
|
-
DERIVED_PREDICATES = [
|
6
|
-
[CONT, {
|
7
|
-
arel_predicate: 'matches'.freeze,
|
8
|
-
formatter: proc { |v| "%#{escape_wildcards(v)}%" }
|
9
|
-
}
|
10
|
-
],
|
11
|
-
['not_cont'.freeze, {
|
12
|
-
arel_predicate: 'does_not_match'.freeze,
|
13
|
-
formatter: proc { |v| "%#{escape_wildcards(v)}%" }
|
14
|
-
}
|
15
|
-
],
|
16
|
-
['i_cont'.freeze, {
|
17
|
-
arel_predicate: 'matches'.freeze,
|
18
|
-
formatter: proc { |v| "%#{escape_wildcards(v.downcase)}%" },
|
19
|
-
case_insensitive: true
|
20
|
-
}
|
21
|
-
],
|
22
|
-
['not_i_cont'.freeze, {
|
23
|
-
arel_predicate: 'does_not_match'.freeze,
|
24
|
-
formatter: proc { |v| "%#{escape_wildcards(v.downcase)}%" },
|
25
|
-
case_insensitive: true
|
26
|
-
}
|
27
|
-
],
|
28
|
-
['start'.freeze, {
|
29
|
-
arel_predicate: 'matches'.freeze,
|
30
|
-
formatter: proc { |v| "#{escape_wildcards(v)}%" }
|
31
|
-
}
|
32
|
-
],
|
33
|
-
['not_start'.freeze, {
|
34
|
-
arel_predicate: 'does_not_match'.freeze,
|
35
|
-
formatter: proc { |v| "#{escape_wildcards(v)}%" }
|
36
|
-
}
|
37
|
-
],
|
38
|
-
['end'.freeze, {
|
39
|
-
arel_predicate: 'matches'.freeze,
|
40
|
-
formatter: proc { |v| "%#{escape_wildcards(v)}" }
|
41
|
-
}
|
42
|
-
],
|
43
|
-
['not_end'.freeze, {
|
44
|
-
arel_predicate: 'does_not_match'.freeze,
|
45
|
-
formatter: proc { |v| "%#{escape_wildcards(v)}" }
|
46
|
-
}
|
47
|
-
],
|
48
|
-
['true'.freeze, {
|
49
|
-
arel_predicate: proc { |v| v ? EQ : NOT_EQ },
|
50
|
-
compounds: false,
|
51
|
-
type: :boolean,
|
52
|
-
validator: proc { |v| BOOLEAN_VALUES.include?(v) },
|
53
|
-
formatter: proc { |v| true }
|
54
|
-
}
|
55
|
-
],
|
56
|
-
['not_true'.freeze, {
|
57
|
-
arel_predicate: proc { |v| v ? NOT_EQ : EQ },
|
58
|
-
compounds: false,
|
59
|
-
type: :boolean,
|
60
|
-
validator: proc { |v| BOOLEAN_VALUES.include?(v) },
|
61
|
-
formatter: proc { |v| true }
|
62
|
-
}
|
63
|
-
],
|
64
|
-
['false'.freeze, {
|
65
|
-
arel_predicate: proc { |v| v ? EQ : NOT_EQ },
|
66
|
-
compounds: false,
|
67
|
-
type: :boolean,
|
68
|
-
validator: proc { |v| BOOLEAN_VALUES.include?(v) },
|
69
|
-
formatter: proc { |v| false }
|
70
|
-
}
|
71
|
-
],
|
72
|
-
['not_false'.freeze, {
|
73
|
-
arel_predicate: proc { |v| v ? NOT_EQ : EQ },
|
74
|
-
compounds: false,
|
75
|
-
type: :boolean,
|
76
|
-
validator: proc { |v| BOOLEAN_VALUES.include?(v) },
|
77
|
-
formatter: proc { |v| false }
|
78
|
-
}
|
79
|
-
],
|
80
|
-
['present'.freeze, {
|
81
|
-
arel_predicate: proc { |v| v ? NOT_EQ_ALL : EQ_ANY },
|
82
|
-
compounds: false,
|
83
|
-
type: :boolean,
|
84
|
-
validator: proc { |v| BOOLEAN_VALUES.include?(v) },
|
85
|
-
formatter: proc { |v| [nil, ''.freeze].freeze }
|
86
|
-
}
|
87
|
-
],
|
88
|
-
['blank'.freeze, {
|
89
|
-
arel_predicate: proc { |v| v ? EQ_ANY : NOT_EQ_ALL },
|
90
|
-
compounds: false,
|
91
|
-
type: :boolean,
|
92
|
-
validator: proc { |v| BOOLEAN_VALUES.include?(v) },
|
93
|
-
formatter: proc { |v| [nil, ''.freeze].freeze }
|
94
|
-
}
|
95
|
-
],
|
96
|
-
['null'.freeze, {
|
97
|
-
arel_predicate: proc { |v| v ? EQ : NOT_EQ },
|
98
|
-
compounds: false,
|
99
|
-
type: :boolean,
|
100
|
-
validator: proc { |v| BOOLEAN_VALUES.include?(v) },
|
101
|
-
formatter: proc { |v| nil }
|
102
|
-
}
|
103
|
-
],
|
104
|
-
['not_null'.freeze, {
|
105
|
-
arel_predicate: proc { |v| v ? NOT_EQ : EQ },
|
106
|
-
compounds: false,
|
107
|
-
type: :boolean,
|
108
|
-
validator: proc { |v| BOOLEAN_VALUES.include?(v) },
|
109
|
-
formatter: proc { |v| nil } }
|
110
|
-
]
|
111
|
-
].freeze
|
112
|
-
|
113
|
-
module_function
|
114
|
-
# replace % \ to \% \\
|
115
|
-
def escape_wildcards(unescaped)
|
116
|
-
case ActiveRecord::Base.connection.adapter_name
|
117
|
-
when "Mysql2".freeze
|
118
|
-
# Necessary for MySQL
|
119
|
-
unescaped.to_s.gsub(/([\\%_])/, '\\\\\\1')
|
120
|
-
when "PostgreSQL".freeze
|
121
|
-
# Necessary for PostgreSQL
|
122
|
-
unescaped.to_s.gsub(/([\\%_.])/, '\\\\\\1')
|
123
|
-
else
|
124
|
-
unescaped
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'ransack/visitor'
|
2
|
-
|
3
|
-
module Ransack
|
4
|
-
class Context
|
5
|
-
attr_reader :arel_visitor
|
6
|
-
|
7
|
-
class << self
|
8
|
-
|
9
|
-
def for_class(klass, options = {})
|
10
|
-
if klass < ActiveRecord::Base
|
11
|
-
Adapters::ActiveRecord::Context.new(klass, options)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def for_object(object, options = {})
|
16
|
-
case object
|
17
|
-
when ActiveRecord::Relation
|
18
|
-
Adapters::ActiveRecord::Context.new(object.klass, options)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
end # << self
|
23
|
-
|
24
|
-
def initialize(object, options = {})
|
25
|
-
@object = relation_for(object)
|
26
|
-
@klass = @object.klass
|
27
|
-
@join_dependency = join_dependency(@object)
|
28
|
-
@join_type = options[:join_type] || Polyamorous::OuterJoin
|
29
|
-
@search_key = options[:search_key] || Ransack.options[:search_key]
|
30
|
-
@associations_pot = {}
|
31
|
-
@tables_pot = {}
|
32
|
-
@lock_associations = []
|
33
|
-
|
34
|
-
@base = @join_dependency.instance_variable_get(:@join_root)
|
35
|
-
end
|
36
|
-
|
37
|
-
def bind_pair_for(key)
|
38
|
-
@bind_pairs ||= {}
|
39
|
-
|
40
|
-
@bind_pairs[key] ||= begin
|
41
|
-
parent, attr_name = get_parent_and_attribute_name(key.to_s)
|
42
|
-
[parent, attr_name] if parent && attr_name
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def klassify(obj)
|
47
|
-
if Class === obj && ::ActiveRecord::Base > obj
|
48
|
-
obj
|
49
|
-
elsif obj.respond_to? :klass
|
50
|
-
obj.klass
|
51
|
-
else
|
52
|
-
raise ArgumentError, "Don't know how to klassify #{obj.inspect}"
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|