rs-activeadmin-searchable_select 4.0.5

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 (145) hide show
  1. checksums.yaml +7 -0
  2. data/.actrc +20 -0
  3. data/.claude/commands/fix-tests.md +203 -0
  4. data/.github/workflows/ci.yml +170 -0
  5. data/.github/workflows/npm-publish.yml +47 -0
  6. data/.gitignore +27 -0
  7. data/.npmignore +58 -0
  8. data/.rspec +2 -0
  9. data/.rubocop.yml +67 -0
  10. data/.yardopts +2 -0
  11. data/AGENTS.md +39 -0
  12. data/Appraisals +15 -0
  13. data/CHANGELOG.md +24 -0
  14. data/CLAUDE.md +104 -0
  15. data/Gemfile +11 -0
  16. data/Gemfile.lock +366 -0
  17. data/LICENSE.txt +25 -0
  18. data/README.md +439 -0
  19. data/Rakefile +4 -0
  20. data/bin/rspec +17 -0
  21. data/config/database.yml +16 -0
  22. data/config.ru +28 -0
  23. data/docs/activeadmin-4-detailed-reference.md +932 -0
  24. data/docs/activeadmin-4-gem-migration-guide.md +313 -0
  25. data/docs/combustion.md +213 -0
  26. data/docs/for-next-session.md +199 -0
  27. data/docs/guide-update-your-app.md +213 -0
  28. data/docs/propshaft-readme.md +121 -0
  29. data/docs/propshaft-upgrade.md +267 -0
  30. data/docs/rails-7-asset-pipeline.md +279 -0
  31. data/docs/setup-activeadmin-app.md +552 -0
  32. data/docs/setup-activeadmin-gem.md +535 -0
  33. data/docs/upload-system.md +225 -0
  34. data/gemfiles/rails_7.x_active_admin_4.x.gemfile +11 -0
  35. data/gemfiles/rails_7.x_active_admin_4.x.gemfile.lock +371 -0
  36. data/gemfiles/rails_8.x_active_admin_4.x.gemfile +11 -0
  37. data/gemfiles/rails_8.x_active_admin_4.x.gemfile.lock +366 -0
  38. data/lefthook.yml +17 -0
  39. data/lib/activeadmin/inputs/filters/searchable_select_input.rb +13 -0
  40. data/lib/activeadmin/inputs/searchable_select_input.rb +11 -0
  41. data/lib/activeadmin/searchable_select/engine.rb +17 -0
  42. data/lib/activeadmin/searchable_select/option_collection.rb +119 -0
  43. data/lib/activeadmin/searchable_select/resource_dsl_extension.rb +56 -0
  44. data/lib/activeadmin/searchable_select/resource_extension.rb +10 -0
  45. data/lib/activeadmin/searchable_select/select_input_extension.rb +159 -0
  46. data/lib/activeadmin/searchable_select/version.rb +5 -0
  47. data/lib/activeadmin/searchable_select.rb +20 -0
  48. data/lib/activeadmin-searchable_select.rb +4 -0
  49. data/lib/generators/active_admin/searchable_select/install/install_generator.rb +217 -0
  50. data/package-lock.json +18 -0
  51. data/package.json +45 -0
  52. data/rs-activeadmin-searchable_select.gemspec +38 -0
  53. data/sonar-project.properties +25 -0
  54. data/spec/features/ajax_params_spec.rb +31 -0
  55. data/spec/features/end_to_end_spec.rb +227 -0
  56. data/spec/features/filter_input_spec.rb +137 -0
  57. data/spec/features/form_input_spec.rb +122 -0
  58. data/spec/features/inline_ajax_setting_spec.rb +26 -0
  59. data/spec/features/input_errors_spec.rb +76 -0
  60. data/spec/features/input_html_options_spec.rb +30 -0
  61. data/spec/features/options_dsl_spec.rb +220 -0
  62. data/spec/features/production_build_spec.rb +108 -0
  63. data/spec/internal/app/admin/categories.rb +26 -0
  64. data/spec/internal/app/admin/dashboard.rb +29 -0
  65. data/spec/internal/app/admin/option_types.rb +19 -0
  66. data/spec/internal/app/admin/option_values.rb +30 -0
  67. data/spec/internal/app/admin/posts.rb +27 -0
  68. data/spec/internal/app/admin/products.rb +22 -0
  69. data/spec/internal/app/admin/rgb_colors.rb +25 -0
  70. data/spec/internal/app/admin/tag_names.rb +21 -0
  71. data/spec/internal/app/admin/test_ajax_params_category.rb +10 -0
  72. data/spec/internal/app/admin/test_ajax_params_post.rb +20 -0
  73. data/spec/internal/app/admin/test_form_post_class.rb +7 -0
  74. data/spec/internal/app/admin/test_form_post_custom.rb +11 -0
  75. data/spec/internal/app/admin/test_form_post_resource.rb +11 -0
  76. data/spec/internal/app/admin/test_form_post_resource_custom.rb +12 -0
  77. data/spec/internal/app/admin/test_inline_ajax_post.rb +9 -0
  78. data/spec/internal/app/admin/test_input_html_post.rb +11 -0
  79. data/spec/internal/app/admin/test_posts_display_text.rb +9 -0
  80. data/spec/internal/app/admin/test_posts_filter.rb +9 -0
  81. data/spec/internal/app/admin/test_posts_named.rb +9 -0
  82. data/spec/internal/app/admin/test_posts_pagination.rb +9 -0
  83. data/spec/internal/app/admin/test_posts_payload_lambda.rb +11 -0
  84. data/spec/internal/app/admin/test_posts_payload_proc.rb +9 -0
  85. data/spec/internal/app/admin/test_posts_scope_lambda.rb +8 -0
  86. data/spec/internal/app/admin/test_posts_scope_params.rb +8 -0
  87. data/spec/internal/app/admin/test_posts_scope_user.rb +8 -0
  88. data/spec/internal/app/admin/test_posts_text_attr.rb +5 -0
  89. data/spec/internal/app/admin/users.rb +23 -0
  90. data/spec/internal/app/admin/variants.rb +31 -0
  91. data/spec/internal/app/assets/config/manifest.js +1 -0
  92. data/spec/internal/app/assets/javascripts/active_admin.js +2 -0
  93. data/spec/internal/app/assets/javascripts/searchable_select_test.js +2 -0
  94. data/spec/internal/app/controllers/application_controller.rb +5 -0
  95. data/spec/internal/app/css/active_admin_source.css +81 -0
  96. data/spec/internal/app/js/active_admin.js +17 -0
  97. data/spec/internal/app/models/article.rb +12 -0
  98. data/spec/internal/app/models/category.rb +12 -0
  99. data/spec/internal/app/models/internal/tag_name.rb +14 -0
  100. data/spec/internal/app/models/internal_tag_name.rb +11 -0
  101. data/spec/internal/app/models/option_type.rb +12 -0
  102. data/spec/internal/app/models/option_value.rb +4 -0
  103. data/spec/internal/app/models/post.rb +15 -0
  104. data/spec/internal/app/models/product.rb +12 -0
  105. data/spec/internal/app/models/rgb_color.rb +16 -0
  106. data/spec/internal/app/models/user.rb +12 -0
  107. data/spec/internal/app/models/variant.rb +12 -0
  108. data/spec/internal/build_activeadmin_css.js +115 -0
  109. data/spec/internal/config/database.yml +7 -0
  110. data/spec/internal/config/environment.rb +48 -0
  111. data/spec/internal/config/initializers/active_admin.rb +53 -0
  112. data/spec/internal/config/initializers/assets.rb +9 -0
  113. data/spec/internal/config/initializers/searchable_select.rb +6 -0
  114. data/spec/internal/config/routes.rb +4 -0
  115. data/spec/internal/config.ru +4 -0
  116. data/spec/internal/db/schema.rb +63 -0
  117. data/spec/internal/db/seeds.rb +88 -0
  118. data/spec/internal/esbuild.config.js +30 -0
  119. data/spec/internal/inject-jquery.js +4 -0
  120. data/spec/internal/log/.gitignore +1 -0
  121. data/spec/internal/package/LICENSE.txt +25 -0
  122. data/spec/internal/package/README.md +439 -0
  123. data/spec/internal/package/package.json +45 -0
  124. data/spec/internal/package/src/index.js +1 -0
  125. data/spec/internal/package/src/searchable_select/init.js +1 -0
  126. data/spec/internal/package/src/searchable_select.css +1 -0
  127. data/spec/internal/package/src/searchable_select.scss +1 -0
  128. data/spec/internal/package-lock.json +1385 -0
  129. data/spec/internal/package.json +26 -0
  130. data/spec/internal/public/favicon.ico +0 -0
  131. data/spec/internal/spec/internal/app/css/active_admin_source.css +38 -0
  132. data/spec/internal/spec/internal/log/test.log +0 -0
  133. data/spec/internal/tailwind-active_admin.config.js +53 -0
  134. data/spec/rails_helper.rb +86 -0
  135. data/spec/spec_helper.rb +137 -0
  136. data/spec/support/active_admin_helpers.rb +17 -0
  137. data/spec/support/capybara.rb +8 -0
  138. data/spec/support/models.rb +88 -0
  139. data/spec/support/pluck_polyfill.rb +12 -0
  140. data/spec/support/reset_settings.rb +5 -0
  141. data/src/index.js +77 -0
  142. data/src/searchable_select/init.js +58 -0
  143. data/src/searchable_select.css +5 -0
  144. data/src/searchable_select.css.map +1 -0
  145. metadata +405 -0
@@ -0,0 +1,366 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ rs-activeadmin-searchable_select (4.0.5)
5
+ activeadmin (~> 4.0.0.beta)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (8.0.2.1)
11
+ actionpack (= 8.0.2.1)
12
+ activesupport (= 8.0.2.1)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (>= 0.6.1)
15
+ zeitwerk (~> 2.6)
16
+ actionmailbox (8.0.2.1)
17
+ actionpack (= 8.0.2.1)
18
+ activejob (= 8.0.2.1)
19
+ activerecord (= 8.0.2.1)
20
+ activestorage (= 8.0.2.1)
21
+ activesupport (= 8.0.2.1)
22
+ mail (>= 2.8.0)
23
+ actionmailer (8.0.2.1)
24
+ actionpack (= 8.0.2.1)
25
+ actionview (= 8.0.2.1)
26
+ activejob (= 8.0.2.1)
27
+ activesupport (= 8.0.2.1)
28
+ mail (>= 2.8.0)
29
+ rails-dom-testing (~> 2.2)
30
+ actionpack (8.0.2.1)
31
+ actionview (= 8.0.2.1)
32
+ activesupport (= 8.0.2.1)
33
+ nokogiri (>= 1.8.5)
34
+ rack (>= 2.2.4)
35
+ rack-session (>= 1.0.1)
36
+ rack-test (>= 0.6.3)
37
+ rails-dom-testing (~> 2.2)
38
+ rails-html-sanitizer (~> 1.6)
39
+ useragent (~> 0.16)
40
+ actiontext (8.0.2.1)
41
+ actionpack (= 8.0.2.1)
42
+ activerecord (= 8.0.2.1)
43
+ activestorage (= 8.0.2.1)
44
+ activesupport (= 8.0.2.1)
45
+ globalid (>= 0.6.0)
46
+ nokogiri (>= 1.8.5)
47
+ actionview (8.0.2.1)
48
+ activesupport (= 8.0.2.1)
49
+ builder (~> 3.1)
50
+ erubi (~> 1.11)
51
+ rails-dom-testing (~> 2.2)
52
+ rails-html-sanitizer (~> 1.6)
53
+ activeadmin (4.0.0.beta16)
54
+ arbre (~> 2.0)
55
+ csv
56
+ formtastic (>= 5.0)
57
+ formtastic_i18n (>= 0.7)
58
+ inherited_resources (~> 2.0)
59
+ kaminari (>= 1.2.1)
60
+ railties (>= 7.0)
61
+ ransack (>= 4.0)
62
+ activejob (8.0.2.1)
63
+ activesupport (= 8.0.2.1)
64
+ globalid (>= 0.3.6)
65
+ activemodel (8.0.2.1)
66
+ activesupport (= 8.0.2.1)
67
+ activerecord (8.0.2.1)
68
+ activemodel (= 8.0.2.1)
69
+ activesupport (= 8.0.2.1)
70
+ timeout (>= 0.4.0)
71
+ activestorage (8.0.2.1)
72
+ actionpack (= 8.0.2.1)
73
+ activejob (= 8.0.2.1)
74
+ activerecord (= 8.0.2.1)
75
+ activesupport (= 8.0.2.1)
76
+ marcel (~> 1.0)
77
+ activesupport (8.0.2.1)
78
+ base64
79
+ benchmark (>= 0.3)
80
+ bigdecimal
81
+ concurrent-ruby (~> 1.0, >= 1.3.1)
82
+ connection_pool (>= 2.2.5)
83
+ drb
84
+ i18n (>= 1.6, < 2)
85
+ logger (>= 1.4.2)
86
+ minitest (>= 5.1)
87
+ securerandom (>= 0.3)
88
+ tzinfo (~> 2.0, >= 2.0.5)
89
+ uri (>= 0.13.1)
90
+ addressable (2.8.7)
91
+ public_suffix (>= 2.0.2, < 7.0)
92
+ appraisal (2.5.0)
93
+ bundler
94
+ rake
95
+ thor (>= 0.14.0)
96
+ arbre (2.2.0)
97
+ activesupport (>= 7.0)
98
+ ast (2.4.3)
99
+ base64 (0.3.0)
100
+ benchmark (0.4.1)
101
+ bigdecimal (3.2.3)
102
+ builder (3.3.0)
103
+ capybara (3.40.0)
104
+ addressable
105
+ matrix
106
+ mini_mime (>= 0.1.3)
107
+ nokogiri (~> 1.11)
108
+ rack (>= 1.6.0)
109
+ rack-test (>= 0.6.3)
110
+ regexp_parser (>= 1.5, < 3.0)
111
+ xpath (~> 3.2)
112
+ capybara-playwright-driver (0.5.7)
113
+ addressable
114
+ capybara
115
+ playwright-ruby-client (>= 1.16.0)
116
+ combustion (1.5.0)
117
+ activesupport (>= 3.0.0)
118
+ railties (>= 3.0.0)
119
+ thor (>= 0.14.6)
120
+ concurrent-ruby (1.3.5)
121
+ connection_pool (2.5.4)
122
+ crass (1.0.6)
123
+ csv (3.3.5)
124
+ database_cleaner-active_record (2.2.2)
125
+ activerecord (>= 5.a)
126
+ database_cleaner-core (~> 2.0)
127
+ database_cleaner-core (2.0.1)
128
+ date (3.4.1)
129
+ diff-lcs (1.6.2)
130
+ docile (1.4.1)
131
+ drb (2.2.3)
132
+ erb (5.0.2)
133
+ erubi (1.13.1)
134
+ formtastic (5.0.0)
135
+ actionpack (>= 6.0.0)
136
+ formtastic_i18n (0.7.0)
137
+ git (1.19.1)
138
+ addressable (~> 2.8)
139
+ rchardet (~> 1.8)
140
+ globalid (1.2.1)
141
+ activesupport (>= 6.1)
142
+ has_scope (0.8.2)
143
+ actionpack (>= 5.2)
144
+ activesupport (>= 5.2)
145
+ i18n (1.14.7)
146
+ concurrent-ruby (~> 1.0)
147
+ inherited_resources (2.1.0)
148
+ actionpack (>= 7.0)
149
+ has_scope (>= 0.6)
150
+ railties (>= 7.0)
151
+ responders (>= 2)
152
+ io-console (0.8.1)
153
+ irb (1.15.2)
154
+ pp (>= 0.6.0)
155
+ rdoc (>= 4.0.0)
156
+ reline (>= 0.4.2)
157
+ json (2.13.2)
158
+ kaminari (1.2.2)
159
+ activesupport (>= 4.1.0)
160
+ kaminari-actionview (= 1.2.2)
161
+ kaminari-activerecord (= 1.2.2)
162
+ kaminari-core (= 1.2.2)
163
+ kaminari-actionview (1.2.2)
164
+ actionview
165
+ kaminari-core (= 1.2.2)
166
+ kaminari-activerecord (1.2.2)
167
+ activerecord
168
+ kaminari-core (= 1.2.2)
169
+ kaminari-core (1.2.2)
170
+ logger (1.7.0)
171
+ loofah (2.24.1)
172
+ crass (~> 1.0.2)
173
+ nokogiri (>= 1.12.0)
174
+ mail (2.8.1)
175
+ mini_mime (>= 0.1.1)
176
+ net-imap
177
+ net-pop
178
+ net-smtp
179
+ marcel (1.0.4)
180
+ matrix (0.4.3)
181
+ mime-types (3.7.0)
182
+ logger
183
+ mime-types-data (~> 3.2025, >= 3.2025.0507)
184
+ mime-types-data (3.2025.0902)
185
+ mini_mime (1.1.5)
186
+ minitest (5.25.5)
187
+ net-imap (0.5.10)
188
+ date
189
+ net-protocol
190
+ net-pop (0.1.2)
191
+ net-protocol
192
+ net-protocol (0.2.2)
193
+ timeout
194
+ net-smtp (0.5.1)
195
+ net-protocol
196
+ nio4r (2.7.4)
197
+ nokogiri (1.18.9-x86_64-linux-gnu)
198
+ racc (~> 1.4)
199
+ parallel (1.27.0)
200
+ parser (3.3.9.0)
201
+ ast (~> 2.4.1)
202
+ racc
203
+ playwright-ruby-client (1.55.0)
204
+ concurrent-ruby (>= 1.1.6)
205
+ mime-types (>= 3.0)
206
+ pp (0.6.2)
207
+ prettyprint
208
+ prettyprint (0.2.0)
209
+ prism (1.4.0)
210
+ propshaft (1.2.1)
211
+ actionpack (>= 7.0.0)
212
+ activesupport (>= 7.0.0)
213
+ rack
214
+ psych (5.2.6)
215
+ date
216
+ stringio
217
+ public_suffix (6.0.2)
218
+ puma (6.6.1)
219
+ nio4r (~> 2.0)
220
+ racc (1.8.1)
221
+ rack (3.2.1)
222
+ rack-session (2.1.1)
223
+ base64 (>= 0.1.0)
224
+ rack (>= 3.0.0)
225
+ rack-test (2.2.0)
226
+ rack (>= 1.3)
227
+ rackup (2.2.1)
228
+ rack (>= 3)
229
+ rails (8.0.2.1)
230
+ actioncable (= 8.0.2.1)
231
+ actionmailbox (= 8.0.2.1)
232
+ actionmailer (= 8.0.2.1)
233
+ actionpack (= 8.0.2.1)
234
+ actiontext (= 8.0.2.1)
235
+ actionview (= 8.0.2.1)
236
+ activejob (= 8.0.2.1)
237
+ activemodel (= 8.0.2.1)
238
+ activerecord (= 8.0.2.1)
239
+ activestorage (= 8.0.2.1)
240
+ activesupport (= 8.0.2.1)
241
+ bundler (>= 1.15.0)
242
+ railties (= 8.0.2.1)
243
+ rails-dom-testing (2.3.0)
244
+ activesupport (>= 5.0.0)
245
+ minitest
246
+ nokogiri (>= 1.6)
247
+ rails-html-sanitizer (1.6.2)
248
+ loofah (~> 2.21)
249
+ nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
250
+ railties (8.0.2.1)
251
+ actionpack (= 8.0.2.1)
252
+ activesupport (= 8.0.2.1)
253
+ irb (~> 1.13)
254
+ rackup (>= 1.0.0)
255
+ rake (>= 12.2)
256
+ thor (~> 1.0, >= 1.2.2)
257
+ zeitwerk (~> 2.6)
258
+ rainbow (2.2.2)
259
+ rake
260
+ rake (13.3.0)
261
+ ransack (4.3.0)
262
+ activerecord (>= 6.1.5)
263
+ activesupport (>= 6.1.5)
264
+ i18n
265
+ rchardet (1.9.0)
266
+ rdoc (6.14.2)
267
+ erb
268
+ psych (>= 4.0.0)
269
+ regexp_parser (2.11.2)
270
+ reline (0.6.2)
271
+ io-console (~> 0.5)
272
+ responders (3.1.1)
273
+ actionpack (>= 5.2)
274
+ railties (>= 5.2)
275
+ rexml (3.4.2)
276
+ rspec-core (3.13.5)
277
+ rspec-support (~> 3.13.0)
278
+ rspec-expectations (3.13.5)
279
+ diff-lcs (>= 1.2.0, < 2.0)
280
+ rspec-support (~> 3.13.0)
281
+ rspec-mocks (3.13.5)
282
+ diff-lcs (>= 1.2.0, < 2.0)
283
+ rspec-support (~> 3.13.0)
284
+ rspec-rails (6.1.5)
285
+ actionpack (>= 6.1)
286
+ activesupport (>= 6.1)
287
+ railties (>= 6.1)
288
+ rspec-core (~> 3.13)
289
+ rspec-expectations (~> 3.13)
290
+ rspec-mocks (~> 3.13)
291
+ rspec-support (~> 3.13)
292
+ rspec-support (3.13.5)
293
+ rspec_junit_formatter (0.6.0)
294
+ rspec-core (>= 2, < 4, != 2.12.0)
295
+ rubocop (1.50.2)
296
+ json (~> 2.3)
297
+ parallel (~> 1.10)
298
+ parser (>= 3.2.0.0)
299
+ rainbow (>= 2.2.2, < 4.0)
300
+ regexp_parser (>= 1.8, < 3.0)
301
+ rexml (>= 3.2.5, < 4.0)
302
+ rubocop-ast (>= 1.28.0, < 2.0)
303
+ ruby-progressbar (~> 1.7)
304
+ unicode-display_width (>= 2.4.0, < 3.0)
305
+ rubocop-ast (1.46.0)
306
+ parser (>= 3.3.7.2)
307
+ prism (~> 1.4)
308
+ ruby-progressbar (1.13.0)
309
+ securerandom (0.4.1)
310
+ semmy (1.2.0)
311
+ git (~> 1.3)
312
+ rainbow (~> 2.1)
313
+ unindent (~> 1.0)
314
+ simplecov (0.22.0)
315
+ docile (~> 1.1)
316
+ simplecov-html (~> 0.11)
317
+ simplecov_json_formatter (~> 0.1)
318
+ simplecov-cobertura (3.1.0)
319
+ rexml
320
+ simplecov (~> 0.19)
321
+ simplecov-html (0.13.2)
322
+ simplecov_json_formatter (0.1.4)
323
+ sqlite3 (2.7.3-x86_64-linux-gnu)
324
+ stringio (3.1.7)
325
+ thor (1.4.0)
326
+ timeout (0.4.3)
327
+ tzinfo (2.0.6)
328
+ concurrent-ruby (~> 1.0)
329
+ unicode-display_width (2.6.0)
330
+ unindent (1.0)
331
+ uri (1.0.3)
332
+ useragent (0.16.11)
333
+ websocket-driver (0.8.0)
334
+ base64
335
+ websocket-extensions (>= 0.1.0)
336
+ websocket-extensions (0.1.5)
337
+ xpath (3.2.0)
338
+ nokogiri (~> 1.8)
339
+ zeitwerk (2.7.3)
340
+
341
+ PLATFORMS
342
+ x86_64-linux
343
+
344
+ DEPENDENCIES
345
+ activeadmin (= 4.0.0.beta16)
346
+ appraisal (~> 2.2)
347
+ bundler (>= 1.5, < 3)
348
+ capybara (~> 3.39)
349
+ capybara-playwright-driver (~> 0.5)
350
+ combustion (~> 1.5)
351
+ database_cleaner-active_record (~> 2.1)
352
+ propshaft
353
+ puma (~> 6.0)
354
+ rails (~> 8.0)
355
+ rake
356
+ rs-activeadmin-searchable_select!
357
+ rspec-rails (~> 6.0)
358
+ rspec_junit_formatter
359
+ rubocop (~> 1.50.0)
360
+ semmy (~> 1.0)
361
+ simplecov
362
+ simplecov-cobertura
363
+ sqlite3 (~> 2.1)
364
+
365
+ BUNDLED WITH
366
+ 2.4.10
data/lefthook.yml ADDED
@@ -0,0 +1,17 @@
1
+ # Lefthook configuration
2
+ # https://github.com/evilmartians/lefthook
3
+
4
+ pre-commit:
5
+ parallel: true
6
+ commands:
7
+ rubocop:
8
+ tags: style ruby
9
+ glob: "*.{rb,rake}"
10
+ run: bundle exec rubocop --force-exclusion {staged_files}
11
+
12
+ pre-push:
13
+ parallel: true
14
+ commands:
15
+ rspec:
16
+ tags: test ruby
17
+ run: bundle exec rspec --format progress
@@ -0,0 +1,13 @@
1
+ module ActiveAdmin
2
+ module Inputs
3
+ module Filters
4
+ # Searchable select input type for ActiveAdmin filters.
5
+ #
6
+ # @see ActiveAdmin::SearchableSelect::SelectInputExtension
7
+ # SelectInputExtension for list of available options.
8
+ class SearchableSelectInput < SelectInput
9
+ include ActiveAdmin::SearchableSelect::SelectInputExtension
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module ActiveAdmin
2
+ module Inputs
3
+ # Searchable select input type for ActiveAdmin filters.
4
+ #
5
+ # @see ActiveAdmin::SearchableSelect::SelectInputExtension
6
+ # SelectInputExtension for list of available options.
7
+ class SearchableSelectInput < Formtastic::Inputs::SelectInput
8
+ include ActiveAdmin::SearchableSelect::SelectInputExtension
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ require 'active_admin'
2
+
3
+ module ActiveAdmin
4
+ module SearchableSelect
5
+ # @api private
6
+ class Engine < ::Rails::Engine
7
+ engine_name 'activeadmin_searchable_select'
8
+
9
+ initializer 'activeadmin_searchable_select.setup' do
10
+ ActiveSupport.on_load(:active_admin) do
11
+ require 'activeadmin/inputs/searchable_select_input'
12
+ require 'activeadmin/inputs/filters/searchable_select_input'
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,119 @@
1
+ module ActiveAdmin
2
+ module SearchableSelect
3
+ # @api private
4
+ class OptionCollection
5
+ def initialize(name, options)
6
+ @name = name
7
+ @scope = extract_scope_option(options)
8
+ @display_text = extract_display_text_option(options)
9
+ @filter = extract_filter_option(options)
10
+ @per_page = options.fetch(:per_page, 10)
11
+ @additional_payload = options.fetch(:additional_payload, {})
12
+ end
13
+
14
+ def scope(template, params)
15
+ case @scope
16
+ when Proc
17
+ if @scope.arity.zero?
18
+ template.instance_exec(&@scope)
19
+ else
20
+ template.instance_exec(params, &@scope)
21
+ end
22
+ else
23
+ @scope
24
+ end
25
+ end
26
+
27
+ def display_text(record)
28
+ @display_text.call(record)
29
+ end
30
+
31
+ def collection_action_name
32
+ "#{@name}_options"
33
+ end
34
+
35
+ def as_json(template, params)
36
+ records, more = fetch_records(template, params)
37
+
38
+ results = records.map do |record|
39
+ {
40
+ id: record.id,
41
+ text: display_text(record)
42
+ }.merge(hash_of_additional_payload(record) || {})
43
+ end
44
+
45
+ { results: results, pagination: { more: more } }
46
+ end
47
+
48
+ private
49
+
50
+ attr_reader :per_page
51
+
52
+ def fetch_records(template, params)
53
+ paginate(filter(scope(template, params), params[:term]),
54
+ params[:page])
55
+ end
56
+
57
+ def filter(scope, term)
58
+ term ? @filter.call(term, scope) : scope
59
+ end
60
+
61
+ def paginate(scope, page_index)
62
+ page_index = page_index.to_i
63
+
64
+ records = scope.limit(per_page + 1).offset(page_index * per_page).to_a
65
+
66
+ [
67
+ records.slice(0, per_page),
68
+ records.size > per_page
69
+ ]
70
+ end
71
+
72
+ def extract_scope_option(options)
73
+ options.fetch(:scope) do
74
+ raise('Missing option: scope. ' \
75
+ 'Pass the collection of items to render options for.')
76
+ end
77
+ end
78
+
79
+ def extract_display_text_option(options)
80
+ options.fetch(:display_text) do
81
+ text_attribute = options.fetch(:text_attribute) do
82
+ raise('Missing option: display_text or text_attribute. ' \
83
+ 'Either pass a proc to determine the display text for a record ' \
84
+ 'or set the text_attribute option.')
85
+ end
86
+
87
+ ->(record) { record.send(text_attribute) }
88
+ end
89
+ end
90
+
91
+ def extract_filter_option(options)
92
+ options.fetch(:filter) do
93
+ text_attribute = options.fetch(:text_attribute) do
94
+ raise('Missing option: filter or text_attribute. ' \
95
+ 'Either pass a proc which filters the scope according to a given ' \
96
+ 'or set the text_attribute option to apply a default Ransack filter.')
97
+ end
98
+
99
+ ->(term, scope) { scope.ransack("#{text_attribute}_cont" => term).result }
100
+ end
101
+ end
102
+
103
+ def build_additional_payload(record)
104
+ case @additional_payload
105
+ when Proc
106
+ @additional_payload.call(record).to_h
107
+ else
108
+ {}
109
+ end
110
+ end
111
+
112
+ def hash_of_additional_payload(record)
113
+ return nil if @additional_payload.nil? && @additional_payload.empty?
114
+
115
+ build_additional_payload(record)
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,56 @@
1
+ module ActiveAdmin
2
+ module SearchableSelect
3
+ # Mixin for ActiveAdmin resource DSL
4
+ module ResourceDSLExtension
5
+ # Define a collection action to serve options JSON data for
6
+ # searchable selects.
7
+ #
8
+ # @param scope [ActiveRecord::Relation, Proc] Either a
9
+ # collection of records to create options for or a proc
10
+ # returning such a collection. Procs are evaluated in the
11
+ # context of the collection action defined by this
12
+ # method. Procs can optionally take a single `params` argument
13
+ # containing data defined under the `params` key of the
14
+ # input's `ajax` option. Required.
15
+ #
16
+ # @param text_attribute [Symbol] Name of attribute to use as
17
+ # display name and to filter by search term.
18
+ #
19
+ # @param display_text [Proc] Takes the record as
20
+ # parameter. Required if `text_attribute` is not present.
21
+ #
22
+ # @param filter [Proc] Takes the search term and an Active
23
+ # Record scope as parameters and needs to return a scope of
24
+ # filtered records. Required if `text_attribute` is not
25
+ # present.
26
+ #
27
+ # @param name [Symbol] Optional collection name if helper is
28
+ # used multiple times within one resource.
29
+ #
30
+ # @param additional_payload [Proc]
31
+ # Adds additional attributes to the results array
32
+ # @example
33
+ #
34
+ # ActiveAdmin.register Tag do
35
+ # searchable_select_options(
36
+ # scope: Color,
37
+ # text_attributes: :title,
38
+ # additional_payload: lambda { |record| { color: record.color } }
39
+ # )
40
+ # end
41
+ # @json
42
+ # {
43
+ # "results": [{ "id": "1", "text": "Red", "color": "#FFF" }],
44
+ # "pagination": { "more": "false" }
45
+ # }
46
+ def searchable_select_options(name: :all, **options)
47
+ option_collection = OptionCollection.new(name, options)
48
+ config.searchable_select_option_collections[name] = option_collection
49
+
50
+ collection_action(option_collection.collection_action_name) do
51
+ render(json: option_collection.as_json(self, params))
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,10 @@
1
+ module ActiveAdmin
2
+ module SearchableSelect
3
+ # @api private
4
+ module ResourceExtension
5
+ def searchable_select_option_collections
6
+ @searchable_select_option_collections ||= {}
7
+ end
8
+ end
9
+ end
10
+ end