administrate_exportable 0.6.3 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8daac2aef4cda63848b4ba2646021b424c598dfb05ba152bd3ddafc1e81c7a84
4
- data.tar.gz: efe0a0bef2ae8ac4293ade2a990477e21fdefbc44bd2cd80cca7c00d784c499c
3
+ metadata.gz: 9cbff1fff937f0640ccdb42b0f80363220ae4d91a8a4f98a22394c2481a3c86a
4
+ data.tar.gz: b54ba5b4180434920f8eddf45ea38b51371d51fef4a61336252c6560edf4c2be
5
5
  SHA512:
6
- metadata.gz: 3d4e9fc50fa6e17d34ffd36afe982506c0b72fd801b78ce85f6a1071642fa6f65bf636109692d47e92aa5a7186bf900ada11b926d54e633289dd8a8208710e67
7
- data.tar.gz: 6b7735fa0be5f7f7cc32dd8241ceabb715153d6a27cce8a877fd087a1209ed0121bea8e29f0e33b2692170fce36ed237ae5db3e7319588305ebe72d7c1ac763f
6
+ metadata.gz: aca50be90261668a6eeabd518cdb12846ffe35e68b61c1196164b352ffa9417295a757981950c66ae968254e1343e8fc00876de9190439f72e10bdbd16b74c0a
7
+ data.tar.gz: 0aa6961811d2dbd28b20af2a9d47bb0e713ce3e6b099b61a712ac2c9de89f5ce7a9e3cd5bdbf114ac7443a85b860711e221401be508775e61205dfca5e92abdd
@@ -0,0 +1,44 @@
1
+ name: Tests
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - "*"
7
+ push:
8
+ branches:
9
+ - main
10
+ jobs:
11
+ tests:
12
+ runs-on: ubuntu-latest
13
+ strategy:
14
+ matrix:
15
+ ruby: ["3.2", "3.3", "3.4", "4.0"]
16
+
17
+ steps:
18
+ - uses: actions/checkout@v7
19
+
20
+ - name: Set up Ruby
21
+ uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby }}
24
+ bundler: default
25
+ bundler-cache: true
26
+
27
+ - name: StandardRb check
28
+ run: bundle exec standardrb --format progress --format github --color
29
+
30
+ - name: Run tests
31
+ run: |
32
+ bundle exec rspec
33
+ docs:
34
+ runs-on: ubuntu-latest
35
+ steps:
36
+ - uses: actions/checkout@v7
37
+ - name: Set up Ruby
38
+ uses: ruby/setup-ruby@v1
39
+ with:
40
+ ruby-version: "4.0"
41
+ bundler: default
42
+ bundler-cache: true
43
+ - name: Build docs
44
+ run: bundle exec rake yard
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ *.gem
9
10
 
10
11
  # rspec failure tracking
11
12
  .rspec_status
data/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 2.7.2
1
+ ruby 4.0.0
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  eval_gemfile File.join(File.dirname(__FILE__), "spec/dummy/Gemfile")
data/Gemfile.lock CHANGED
@@ -1,91 +1,137 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- administrate_exportable (0.6.2)
4
+ administrate_exportable (0.8.0)
5
5
  actionview (>= 5.2.2.1)
6
6
  administrate (>= 0.17.0)
7
+ csv (~> 3.0)
7
8
  rails (>= 4.2)
8
9
  railties (>= 5.2.2.1)
9
10
 
10
11
  GEM
11
12
  remote: https://rubygems.org/
12
13
  specs:
13
- actioncable (5.2.8)
14
- actionpack (= 5.2.8)
14
+ actioncable (7.1.6)
15
+ actionpack (= 7.1.6)
16
+ activesupport (= 7.1.6)
15
17
  nio4r (~> 2.0)
16
18
  websocket-driver (>= 0.6.1)
17
- actionmailer (5.2.8)
18
- actionpack (= 5.2.8)
19
- actionview (= 5.2.8)
20
- activejob (= 5.2.8)
19
+ zeitwerk (~> 2.6)
20
+ actionmailbox (7.1.6)
21
+ actionpack (= 7.1.6)
22
+ activejob (= 7.1.6)
23
+ activerecord (= 7.1.6)
24
+ activestorage (= 7.1.6)
25
+ activesupport (= 7.1.6)
26
+ mail (>= 2.7.1)
27
+ net-imap
28
+ net-pop
29
+ net-smtp
30
+ actionmailer (7.1.6)
31
+ actionpack (= 7.1.6)
32
+ actionview (= 7.1.6)
33
+ activejob (= 7.1.6)
34
+ activesupport (= 7.1.6)
21
35
  mail (~> 2.5, >= 2.5.4)
22
- rails-dom-testing (~> 2.0)
23
- actionpack (5.2.8)
24
- actionview (= 5.2.8)
25
- activesupport (= 5.2.8)
26
- rack (~> 2.0, >= 2.0.8)
36
+ net-imap
37
+ net-pop
38
+ net-smtp
39
+ rails-dom-testing (~> 2.2)
40
+ actionpack (7.1.6)
41
+ actionview (= 7.1.6)
42
+ activesupport (= 7.1.6)
43
+ cgi
44
+ nokogiri (>= 1.8.5)
45
+ racc
46
+ rack (>= 2.2.4)
47
+ rack-session (>= 1.0.1)
27
48
  rack-test (>= 0.6.3)
28
- rails-dom-testing (~> 2.0)
29
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
30
- actionview (5.2.8)
31
- activesupport (= 5.2.8)
49
+ rails-dom-testing (~> 2.2)
50
+ rails-html-sanitizer (~> 1.6)
51
+ actiontext (7.1.6)
52
+ actionpack (= 7.1.6)
53
+ activerecord (= 7.1.6)
54
+ activestorage (= 7.1.6)
55
+ activesupport (= 7.1.6)
56
+ globalid (>= 0.6.0)
57
+ nokogiri (>= 1.8.5)
58
+ actionview (7.1.6)
59
+ activesupport (= 7.1.6)
32
60
  builder (~> 3.1)
33
- erubi (~> 1.4)
34
- rails-dom-testing (~> 2.0)
35
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
36
- activejob (5.2.8)
37
- activesupport (= 5.2.8)
61
+ cgi
62
+ erubi (~> 1.11)
63
+ rails-dom-testing (~> 2.2)
64
+ rails-html-sanitizer (~> 1.6)
65
+ activejob (7.1.6)
66
+ activesupport (= 7.1.6)
38
67
  globalid (>= 0.3.6)
39
- activemodel (5.2.8)
40
- activesupport (= 5.2.8)
41
- activerecord (5.2.8)
42
- activemodel (= 5.2.8)
43
- activesupport (= 5.2.8)
44
- arel (>= 9.0)
45
- activestorage (5.2.8)
46
- actionpack (= 5.2.8)
47
- activerecord (= 5.2.8)
48
- marcel (~> 1.0.0)
49
- activesupport (5.2.8)
68
+ activemodel (7.1.6)
69
+ activesupport (= 7.1.6)
70
+ activerecord (7.1.6)
71
+ activemodel (= 7.1.6)
72
+ activesupport (= 7.1.6)
73
+ timeout (>= 0.4.0)
74
+ activestorage (7.1.6)
75
+ actionpack (= 7.1.6)
76
+ activejob (= 7.1.6)
77
+ activerecord (= 7.1.6)
78
+ activesupport (= 7.1.6)
79
+ marcel (~> 1.0)
80
+ activesupport (7.1.6)
81
+ base64
82
+ benchmark (>= 0.3)
83
+ bigdecimal
50
84
  concurrent-ruby (~> 1.0, >= 1.0.2)
51
- i18n (>= 0.7, < 2)
52
- minitest (~> 5.1)
53
- tzinfo (~> 1.1)
54
- administrate (0.17.0)
85
+ connection_pool (>= 2.2.5)
86
+ drb
87
+ i18n (>= 1.6, < 2)
88
+ logger (>= 1.4.2)
89
+ minitest (>= 5.1)
90
+ mutex_m
91
+ securerandom (>= 0.3)
92
+ tzinfo (~> 2.0)
93
+ administrate (0.19.0)
55
94
  actionpack (>= 5.0)
56
95
  actionview (>= 5.0)
57
96
  activerecord (>= 5.0)
58
- datetime_picker_rails (~> 0.0.7)
59
97
  jquery-rails (>= 4.0)
60
98
  kaminari (>= 1.0)
61
- momentjs-rails (~> 2.8)
62
99
  sassc-rails (~> 2.1)
63
100
  selectize-rails (~> 0.6)
64
- administrate-field-enumerate (0.0.2)
65
- administrate
66
- enumerate_it
67
- rails (>= 4.2, < 7.0)
68
- arel (9.0.0)
69
- builder (3.2.4)
70
- byebug (11.1.3)
101
+ ast (2.4.3)
102
+ base64 (0.3.0)
103
+ benchmark (0.5.0)
104
+ bigdecimal (4.0.1)
105
+ builder (3.3.0)
106
+ byebug (12.0.0)
107
+ cgi (0.5.1)
71
108
  coderay (1.1.3)
72
- concurrent-ruby (1.1.10)
109
+ concurrent-ruby (1.3.6)
110
+ connection_pool (2.5.5)
73
111
  crass (1.0.6)
74
- datetime_picker_rails (0.0.7)
75
- momentjs-rails (>= 2.8.1)
76
- diff-lcs (1.5.0)
77
- enumerate_it (3.2.2)
78
- activesupport (>= 5.0.7.2)
79
- erubi (1.10.0)
80
- ffi (1.15.5)
81
- globalid (1.0.0)
82
- activesupport (>= 5.0)
83
- i18n (1.10.0)
112
+ csv (3.3.5)
113
+ date (3.5.1)
114
+ diff-lcs (1.6.2)
115
+ drb (2.2.3)
116
+ erb (4.0.4)
117
+ cgi (>= 0.3.3)
118
+ erubi (1.13.1)
119
+ ffi (1.17.3)
120
+ ffi (1.17.3-arm64-darwin)
121
+ globalid (1.3.0)
122
+ activesupport (>= 6.1)
123
+ i18n (1.14.8)
84
124
  concurrent-ruby (~> 1.0)
85
- jquery-rails (4.4.0)
125
+ io-console (0.8.2)
126
+ irb (1.16.0)
127
+ pp (>= 0.6.0)
128
+ rdoc (>= 4.0.0)
129
+ reline (>= 0.4.2)
130
+ jquery-rails (4.6.1)
86
131
  rails-dom-testing (>= 1, < 3)
87
132
  railties (>= 4.2.0)
88
133
  thor (>= 0.14, < 2.0)
134
+ json (2.18.1)
89
135
  kaminari (1.2.2)
90
136
  activesupport (>= 4.1.0)
91
137
  kaminari-actionview (= 1.2.2)
@@ -98,75 +144,142 @@ GEM
98
144
  activerecord
99
145
  kaminari-core (= 1.2.2)
100
146
  kaminari-core (1.2.2)
101
- loofah (2.18.0)
147
+ language_server-protocol (3.17.0.5)
148
+ lint_roller (1.1.0)
149
+ logger (1.7.0)
150
+ loofah (2.25.0)
102
151
  crass (~> 1.0.2)
103
- nokogiri (>= 1.5.9)
104
- mail (2.7.1)
152
+ nokogiri (>= 1.12.0)
153
+ mail (2.9.0)
154
+ logger
105
155
  mini_mime (>= 0.1.1)
106
- marcel (1.0.2)
107
- method_source (1.0.0)
108
- mini_mime (1.1.2)
109
- mini_portile2 (2.8.0)
110
- minitest (5.15.0)
111
- momentjs-rails (2.29.1.1)
112
- railties (>= 3.1)
113
- nio4r (2.5.8)
114
- nokogiri (1.13.6)
115
- mini_portile2 (~> 2.8.0)
156
+ net-imap
157
+ net-pop
158
+ net-smtp
159
+ marcel (1.1.0)
160
+ method_source (1.1.0)
161
+ mini_mime (1.1.5)
162
+ mini_portile2 (2.8.9)
163
+ minitest (5.27.0)
164
+ mutex_m (0.3.0)
165
+ net-imap (0.5.13)
166
+ date
167
+ net-protocol
168
+ net-pop (0.1.2)
169
+ net-protocol
170
+ net-protocol (0.2.2)
171
+ timeout
172
+ net-smtp (0.5.1)
173
+ net-protocol
174
+ nio4r (2.7.5)
175
+ nokogiri (1.19.4)
176
+ mini_portile2 (~> 2.8.2)
177
+ racc (~> 1.4)
178
+ nokogiri (1.19.4-arm64-darwin)
116
179
  racc (~> 1.4)
117
- pry (0.13.1)
180
+ parallel (1.27.0)
181
+ parser (3.3.10.1)
182
+ ast (~> 2.4.1)
183
+ racc
184
+ pp (0.6.3)
185
+ prettyprint
186
+ prettyprint (0.2.0)
187
+ prism (1.9.0)
188
+ pry (0.15.2)
118
189
  coderay (~> 1.1)
119
190
  method_source (~> 1.0)
120
- pry-byebug (3.9.0)
121
- byebug (~> 11.0)
122
- pry (~> 0.13.0)
123
- racc (1.6.0)
124
- rack (2.2.3)
125
- rack-test (1.1.0)
126
- rack (>= 1.0, < 3)
127
- rails (5.2.8)
128
- actioncable (= 5.2.8)
129
- actionmailer (= 5.2.8)
130
- actionpack (= 5.2.8)
131
- actionview (= 5.2.8)
132
- activejob (= 5.2.8)
133
- activemodel (= 5.2.8)
134
- activerecord (= 5.2.8)
135
- activestorage (= 5.2.8)
136
- activesupport (= 5.2.8)
137
- bundler (>= 1.3.0)
138
- railties (= 5.2.8)
139
- sprockets-rails (>= 2.0.0)
140
- rails-dom-testing (2.0.3)
141
- activesupport (>= 4.2.0)
191
+ pry-byebug (3.11.0)
192
+ byebug (~> 12.0)
193
+ pry (>= 0.13, < 0.16)
194
+ psych (5.3.1)
195
+ date
196
+ stringio
197
+ racc (1.8.1)
198
+ rack (3.2.4)
199
+ rack-session (2.1.1)
200
+ base64 (>= 0.1.0)
201
+ rack (>= 3.0.0)
202
+ rack-test (2.2.0)
203
+ rack (>= 1.3)
204
+ rackup (2.3.1)
205
+ rack (>= 3)
206
+ rails (7.1.6)
207
+ actioncable (= 7.1.6)
208
+ actionmailbox (= 7.1.6)
209
+ actionmailer (= 7.1.6)
210
+ actionpack (= 7.1.6)
211
+ actiontext (= 7.1.6)
212
+ actionview (= 7.1.6)
213
+ activejob (= 7.1.6)
214
+ activemodel (= 7.1.6)
215
+ activerecord (= 7.1.6)
216
+ activestorage (= 7.1.6)
217
+ activesupport (= 7.1.6)
218
+ bundler (>= 1.15.0)
219
+ railties (= 7.1.6)
220
+ rails-dom-testing (2.3.0)
221
+ activesupport (>= 5.0.0)
222
+ minitest
142
223
  nokogiri (>= 1.6)
143
- rails-html-sanitizer (1.4.2)
144
- loofah (~> 2.3)
145
- railties (5.2.8)
146
- actionpack (= 5.2.8)
147
- activesupport (= 5.2.8)
148
- method_source
149
- rake (>= 0.8.7)
150
- thor (>= 0.19.0, < 2.0)
151
- rake (13.0.6)
224
+ rails-html-sanitizer (1.6.2)
225
+ loofah (~> 2.21)
226
+ 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)
227
+ railties (7.1.6)
228
+ actionpack (= 7.1.6)
229
+ activesupport (= 7.1.6)
230
+ cgi
231
+ irb
232
+ rackup (>= 1.0.0)
233
+ rake (>= 12.2)
234
+ thor (~> 1.0, >= 1.2.2)
235
+ tsort (>= 0.2)
236
+ zeitwerk (~> 2.6)
237
+ rainbow (3.1.1)
238
+ rake (13.3.1)
152
239
  rb-readline (0.5.5)
153
- rspec-core (3.9.3)
154
- rspec-support (~> 3.9.3)
155
- rspec-expectations (3.9.4)
240
+ rdoc (7.1.0)
241
+ erb
242
+ psych (>= 4.0.0)
243
+ tsort
244
+ regexp_parser (2.11.3)
245
+ reline (0.6.3)
246
+ io-console (~> 0.5)
247
+ rspec-core (3.13.6)
248
+ rspec-support (~> 3.13.0)
249
+ rspec-expectations (3.13.5)
156
250
  diff-lcs (>= 1.2.0, < 2.0)
157
- rspec-support (~> 3.9.0)
158
- rspec-mocks (3.9.1)
251
+ rspec-support (~> 3.13.0)
252
+ rspec-mocks (3.13.7)
159
253
  diff-lcs (>= 1.2.0, < 2.0)
160
- rspec-support (~> 3.9.0)
161
- rspec-rails (3.9.1)
162
- actionpack (>= 3.0)
163
- activesupport (>= 3.0)
164
- railties (>= 3.0)
165
- rspec-core (~> 3.9.0)
166
- rspec-expectations (~> 3.9.0)
167
- rspec-mocks (~> 3.9.0)
168
- rspec-support (~> 3.9.0)
169
- rspec-support (3.9.4)
254
+ rspec-support (~> 3.13.0)
255
+ rspec-rails (6.1.5)
256
+ actionpack (>= 6.1)
257
+ activesupport (>= 6.1)
258
+ railties (>= 6.1)
259
+ rspec-core (~> 3.13)
260
+ rspec-expectations (~> 3.13)
261
+ rspec-mocks (~> 3.13)
262
+ rspec-support (~> 3.13)
263
+ rspec-support (3.13.7)
264
+ rubocop (1.82.1)
265
+ json (~> 2.3)
266
+ language_server-protocol (~> 3.17.0.2)
267
+ lint_roller (~> 1.1.0)
268
+ parallel (~> 1.10)
269
+ parser (>= 3.3.0.2)
270
+ rainbow (>= 2.2.2, < 4.0)
271
+ regexp_parser (>= 2.9.3, < 3.0)
272
+ rubocop-ast (>= 1.48.0, < 2.0)
273
+ ruby-progressbar (~> 1.7)
274
+ unicode-display_width (>= 2.4.0, < 4.0)
275
+ rubocop-ast (1.49.0)
276
+ parser (>= 3.3.7.2)
277
+ prism (~> 1.7)
278
+ rubocop-performance (1.26.1)
279
+ lint_roller (~> 1.1)
280
+ rubocop (>= 1.75.0, < 2.0)
281
+ rubocop-ast (>= 1.47.1, < 2.0)
282
+ ruby-progressbar (1.13.0)
170
283
  sassc (2.4.0)
171
284
  ffi (~> 1.9)
172
285
  sassc-rails (2.1.2)
@@ -175,40 +288,63 @@ GEM
175
288
  sprockets (> 3.0)
176
289
  sprockets-rails
177
290
  tilt
291
+ securerandom (0.4.1)
178
292
  selectize-rails (0.12.6)
179
- sprockets (4.0.3)
293
+ sprockets (4.2.2)
180
294
  concurrent-ruby (~> 1.0)
181
- rack (> 1, < 3)
182
- sprockets-rails (3.4.2)
183
- actionpack (>= 5.2)
184
- activesupport (>= 5.2)
295
+ logger
296
+ rack (>= 2.2.4, < 4)
297
+ sprockets-rails (3.5.2)
298
+ actionpack (>= 6.1)
299
+ activesupport (>= 6.1)
185
300
  sprockets (>= 3.0.0)
186
- sqlite3 (1.4.2)
187
- thor (1.2.1)
188
- thread_safe (0.3.6)
189
- tilt (2.0.10)
190
- tzinfo (1.2.9)
191
- thread_safe (~> 0.1)
192
- websocket-driver (0.7.5)
301
+ sqlite3 (2.10.1)
302
+ mini_portile2 (~> 2.8.0)
303
+ sqlite3 (2.10.1-arm64-darwin)
304
+ standard (1.53.0)
305
+ language_server-protocol (~> 3.17.0.2)
306
+ lint_roller (~> 1.0)
307
+ rubocop (~> 1.82.0)
308
+ standard-custom (~> 1.0.0)
309
+ standard-performance (~> 1.8)
310
+ standard-custom (1.0.2)
311
+ lint_roller (~> 1.0)
312
+ rubocop (~> 1.50)
313
+ standard-performance (1.9.0)
314
+ lint_roller (~> 1.1)
315
+ rubocop-performance (~> 1.26.0)
316
+ stringio (3.2.0)
317
+ thor (1.5.0)
318
+ tilt (2.7.0)
319
+ timeout (0.6.0)
320
+ tsort (0.2.0)
321
+ tzinfo (2.0.6)
322
+ concurrent-ruby (~> 1.0)
323
+ unicode-display_width (3.2.0)
324
+ unicode-emoji (~> 4.1)
325
+ unicode-emoji (4.2.0)
326
+ websocket-driver (0.8.0)
327
+ base64
193
328
  websocket-extensions (>= 0.1.0)
194
329
  websocket-extensions (0.1.5)
330
+ yard (0.9.38)
331
+ zeitwerk (2.6.18)
195
332
 
196
333
  PLATFORMS
334
+ arm64-darwin
197
335
  ruby
198
336
 
199
337
  DEPENDENCIES
200
- administrate (~> 0.17.0)
201
- administrate-field-enumerate
338
+ administrate (~> 0.19.0)
202
339
  administrate_exportable!
203
340
  byebug
204
341
  pry-byebug
205
- rails (~> 5.2.3)
342
+ rails (~> 7.1.0)
206
343
  rb-readline
207
- rspec-rails (~> 3.8)
344
+ rspec-rails (~> 6.0)
208
345
  sqlite3
209
-
210
- RUBY VERSION
211
- ruby 2.7.2p137
346
+ standard
347
+ yard
212
348
 
213
349
  BUNDLED WITH
214
- 2.2.17
350
+ 2.5.11
data/README.md CHANGED
@@ -17,15 +17,19 @@ Or install it yourself as:
17
17
  ## Usage
18
18
 
19
19
  For each resource you want to be exportable, add the following line to the their respective Administrate controller.
20
+
20
21
  ```ruby
21
22
  include AdministrateExportable::Exporter
22
23
  ```
24
+
23
25
  and the following line in the `config/routes.rb` file, correctly nested on resources
26
+
24
27
  ```ruby
25
28
  get :export, on: :collection
26
29
  ```
27
30
 
28
31
  Example:
32
+
29
33
  ```ruby
30
34
  namespace :admin do
31
35
  resources :organizations do
@@ -37,6 +41,7 @@ namespace :admin do
37
41
  By default all the attributes from `ATTRIBUTE_TYPES` will be exported. If you want to exclude an attribute, you can use the option: `export: false`.
38
42
 
39
43
  Example:
44
+
40
45
  ```ruby
41
46
  class BusinessDashboard < Administrate::BaseDashboard
42
47
  ATTRIBUTE_TYPES = {
@@ -49,14 +54,16 @@ class BusinessDashboard < Administrate::BaseDashboard
49
54
  For the default field types from Administrate, we export the values you got from the partial `views/fields/index`. And if it is a custom field, we just run `field.to_s`.
50
55
  But if you want to specify the value to be exported, you can use the option `transform_on_export`, to pass a `Proc` that receives the `field`.
51
56
  Example:
57
+
52
58
  ```ruby
53
59
  ATTRIBUTE_TYPES = {
54
60
  created_at: Field::DateTime.with_options(transform_on_export: -> (field) { field.data.strftime("%F") })
55
61
  ```
56
62
 
57
63
  By default the gem adds the Export button to the partial `views/admin/application/_index_header.html.erb`. But if you have your own Administrate `index` views or override that partial in your application you can add the link manually:
64
+
58
65
  ```ruby
59
- link_to('Export', [:export, namespace.to_sym, page.resource_name.to_s.pluralize.to_sym, sanitized_order_params(page, :id).to_h.merge(format: :csv)], class: 'button') if valid_action?(:export)
66
+ link_to('Export', url_for(sanitized_order_params(page, :id).to_h.merge(action: :export, format: :csv)), class: 'button', target: '_blank', data: { turbolinks: false, turbo: false }) if existing_action?(resource_class, :export) && authorized_action?(resource_name, :export)
60
67
  ```
61
68
 
62
69
  Example:
@@ -71,17 +78,59 @@ Example:
71
78
  ),
72
79
  [:new, namespace.to_sym, page.resource_path.to_sym],
73
80
  class: "button",
74
- ) if valid_action?(:new) && show_action?(:new, new_resource) %>
81
+ ) if existing_action?(resource_class, :new) && authorized_action?(new_resource, :new) %>
75
82
 
76
83
  <%= link_to(
77
84
  'Export',
78
- [:export, namespace.to_sym, page.resource_name.to_s.pluralize.to_sym, sanitized_order_params(page, :id).to_h.merge(format: :csv)],
79
- class: 'button'
80
- ) if valid_action?(:export) %>
85
+ url_for(sanitized_order_params(page, :id).to_h.merge(action: :export, format: :csv)),
86
+ class: 'button',
87
+ target: '_blank',
88
+ data: { turbolinks: false, turbo: false }
89
+ ) if existing_action?(resource_class, :export) && authorized_action?(resource_name, :export) %>
81
90
  </div>
82
91
  ....
83
92
  ```
84
93
 
94
+ The link uses `url_for(action: :export)` so it works regardless of the route name (e.g. models with plural names such as `UserSettings`, whose collection routes end in `_index`), and sets `data-turbolinks="false"`/`data-turbo="false"` so the CSV is downloaded instead of being rendered by Turbolinks/Turbo.
95
+
96
+ ### Associations and performance
97
+
98
+ Associations (`Field::BelongsTo`, `Field::HasMany`, `Field::HasOne`, `Field::Polymorphic`, ...) that are exported are preloaded automatically to avoid N+1 queries. Associations excluded with `export: false` are not loaded.
99
+
100
+ If your `transform_on_export` procs access nested associations, you can preload them by overriding `scoped_resource` in your controller:
101
+
102
+ ```ruby
103
+ def scoped_resource
104
+ return super.preload(organizations: :address) if action_name == "export"
105
+
106
+ super
107
+ end
108
+ ```
109
+
110
+ ### Using with Pundit
111
+
112
+ If you are using [Pundit](https://github.com/varvet/pundit) in your project you will receive an error saying `undefined method 'export?' for #<Admin::OrganizationPolicy>`. This is because the `export` action is not defined in the policy.
113
+
114
+ To fix this issue you need to add the `export` action to the policy and define the logic for who can export the resource.
115
+
116
+ Example:
117
+
118
+ ```ruby
119
+ module Admin
120
+ class OrganizationPolicy < ApplicationPolicy
121
+ # ... other methods ...
122
+
123
+ def export?
124
+ # Define the logic for who can export organizations
125
+ # For example, allow only admins to export:
126
+ user.admin?
127
+ end
128
+
129
+ # ... other methods ...
130
+ end
131
+ end
132
+ ```
133
+
85
134
  ## Development
86
135
 
87
136
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
+ require "yard"
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
6
+ YARD::Rake::YardocTask.new
5
7
 
6
- task :default => :spec
8
+ task default: :spec
@@ -1,40 +1,30 @@
1
-
2
1
  lib = File.expand_path("../lib", __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require "administrate_exportable/version"
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "administrate_exportable"
8
- spec.version = AdministrateExportable::VERSION
9
- spec.authors = ["Jônatas Rancan", "Andrei Bondarev"]
10
- spec.email = ["hello@sourcelabs.io"]
11
- spec.homepage = 'https://github.com/SourceLabsLLC/administrate_exportable'
12
- spec.summary = "Simple plugin to add CSV export feature to Administrate"
13
- spec.description = spec.summary
14
- spec.license = "MIT"
6
+ spec.name = "administrate_exportable"
7
+ spec.version = AdministrateExportable::VERSION
8
+ spec.authors = ["Jônatas Rancan", "Andrei Bondarev"]
9
+ spec.email = ["hello@sourcelabs.io"]
10
+ spec.homepage = "https://github.com/SourceLabsLLC/administrate_exportable"
11
+ spec.summary = "Simple plugin to add CSV export feature to Administrate"
12
+ spec.description = spec.summary
13
+ spec.license = "MIT"
15
14
 
16
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
- # to allow pushing to a single host or delete this section to allow pushing to any host.
18
- # if spec.respond_to?(:metadata)
19
- # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
20
- # else
21
- # raise "RubyGems 2.0 or newer is required to protect against " \
22
- # "public gem pushes."
23
- # end
15
+ spec.metadata["source_code_uri"] = spec.homepage
16
+ spec.metadata["bug_tracker_uri"] = "#{spec.homepage}/issues"
24
17
 
25
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
19
  f.match(%r{^(test|spec|features)/})
27
20
  end
28
- spec.bindir = "exe"
29
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
23
  spec.require_paths = ["lib"]
31
24
 
32
- spec.add_development_dependency "bundler", "~> 1.16"
33
- spec.add_development_dependency "rake", "~> 10.0"
34
- spec.add_development_dependency "rspec", "~> 3.0"
35
- spec.add_development_dependency "pry-byebug", "~> 3.0"
36
- spec.add_dependency 'administrate','>= 0.17.0'
37
- spec.add_dependency 'rails', '>= 4.2'
38
- spec.add_dependency 'actionview', '>= 5.2.2.1'
39
- spec.add_dependency 'railties', '>= 5.2.2.1'
25
+ spec.add_dependency "administrate", ">= 0.17.0"
26
+ spec.add_dependency "rails", ">= 4.2"
27
+ spec.add_dependency "actionview", ">= 5.2.2.1"
28
+ spec.add_dependency "railties", ">= 5.2.2.1"
29
+ spec.add_dependency "csv", "~> 3.0"
40
30
  end
@@ -27,9 +27,10 @@
27
27
 
28
28
  <%= link_to(
29
29
  'Export',
30
- [:export, namespace, page.resource_name.to_s.pluralize.to_sym, sanitized_order_params(page, :id).to_h.merge(format: :csv)],
30
+ url_for(sanitized_order_params(page, :id).to_h.merge(action: :export, format: :csv)),
31
31
  class: 'button',
32
- target: '_blank'
33
- ) if valid_action?(:export) && show_action?(:export, resource_name) %>
32
+ target: '_blank',
33
+ data: { turbolinks: false, turbo: false }
34
+ ) if existing_action?(resource_class, :export) && authorized_action?(resource_name, :export) %>
34
35
  </div>
35
36
  </header>
@@ -1 +1,2 @@
1
- <%= paginate resources, param_name: AdministrateExportable::PAGE_PARAM %>
1
+ <% param_name = local_assigns.fetch(:param_name, AdministrateExportable::PAGE_PARAM) %>
2
+ <%= paginate resources, param_name: param_name %>
@@ -10,9 +10,12 @@ module AdministrateExportable
10
10
  def exportable
11
11
  define_method(:export) do
12
12
  search_term = params[:search].to_s.strip
13
- resources = Administrate::Search.new(scoped_resource,
14
- dashboard,
15
- search_term).run
13
+ resources = if respond_to?(:filter_resources, true)
14
+ filter_resources(scoped_resource, search_term: search_term)
15
+ else
16
+ # Administrate < 0.18 has no filter_resources hook
17
+ Administrate::Search.new(scoped_resource, dashboard, search_term).run
18
+ end
16
19
  resources = apply_collection_includes(resources)
17
20
  resources = order.apply(resources)
18
21
 
@@ -1,4 +1,4 @@
1
- require 'csv'
1
+ require "csv"
2
2
 
3
3
  module AdministrateExportable
4
4
  class ExporterService
@@ -7,14 +7,13 @@ module AdministrateExportable
7
7
  end
8
8
 
9
9
  def initialize(dashboard, resource_class, resources)
10
- @dashboard = dashboard
10
+ @dashboard = dashboard.is_a?(Class) ? dashboard.new : dashboard
11
11
  @resource_class = resource_class
12
12
  @resources = resources
13
13
  end
14
14
 
15
15
  def csv
16
16
  CSV.generate(headers: true) do |csv|
17
-
18
17
  csv << headers
19
18
 
20
19
  collection.find_each do |record|
@@ -30,7 +29,7 @@ module AdministrateExportable
30
29
  attr_reader :dashboard, :resource_class, :resources, :sanitizer
31
30
 
32
31
  def record_attribute(record, attribute_key, attribute_type)
33
- field = attribute_type.new(attribute_key, record.send(attribute_key), 'index', resource: record)
32
+ field = attribute_type.new(attribute_key, record.send(attribute_key), "index", resource: record)
34
33
  transform_on_export = attribute_type.respond_to?(:options) && attribute_type.options[:transform_on_export]
35
34
 
36
35
  if transform_on_export.is_a? Proc
@@ -41,7 +40,7 @@ module AdministrateExportable
41
40
  when Administrate::Field::BelongsTo.to_s, Administrate::Field::HasOne.to_s, Administrate::Field::Polymorphic.to_s
42
41
  field.display_associated_resource if field.data
43
42
  when Administrate::Field::HasMany.to_s
44
- field.data.count if field.data
43
+ field.data&.size
45
44
  when Administrate::Field::DateTime.to_s
46
45
  field.datetime if field.data
47
46
  when Administrate::Field::Date.to_s
@@ -61,29 +60,38 @@ module AdministrateExportable
61
60
  attributes_to_export.map do |attribute_key, _|
62
61
  attr_key = attribute_key.to_s
63
62
 
64
- if attr_key.include?('_id')
63
+ if attr_key.include?("_id")
65
64
  attr_key
66
65
  else
67
- I18n.t(
66
+ I18n.t(
68
67
  "helpers.label.#{resource_class.name.downcase}.#{attr_key}",
69
- default: attr_key,
68
+ default: attr_key
70
69
  ).titleize
71
70
  end
72
71
  end
73
72
  end
74
73
 
75
74
  def attributes_to_export
76
- @attributes_to_export ||= begin
77
- dashboard.class::ATTRIBUTE_TYPES.select do |attribute_key, attribute_type|
78
- attribute_options = attribute_type.try(:options)
75
+ @attributes_to_export ||= dashboard.attribute_types.select do |attribute_key, attribute_type|
76
+ attribute_options = attribute_type.try(:options)
79
77
 
80
- !attribute_options || attribute_options[:export] != false
81
- end
78
+ !attribute_options || attribute_options[:export] != false
82
79
  end
83
80
  end
84
81
 
85
82
  def collection
86
- resources
83
+ return resources if associations_to_preload.empty?
84
+
85
+ resources.preload(*associations_to_preload)
86
+ end
87
+
88
+ # Preload every exported association to avoid N+1 queries
89
+ def associations_to_preload
90
+ @associations_to_preload ||= attributes_to_export.select do |attribute_key, attribute_type|
91
+ attribute_type.respond_to?(:associative?) &&
92
+ attribute_type.associative? &&
93
+ resource_class.reflect_on_association(attribute_key)
94
+ end.keys
87
95
  end
88
96
  end
89
97
  end
@@ -1,3 +1,3 @@
1
1
  module AdministrateExportable
2
- VERSION = "0.6.3"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -4,7 +4,7 @@ require "administrate_exportable/exporter"
4
4
  require "administrate/version"
5
5
 
6
6
  module AdministrateExportable
7
- PAGE_PARAM = Gem::Version.create(Administrate::VERSION) >= Gem::Version.create('0.15.0') ? '_page' : 'page'
7
+ PAGE_PARAM = (Gem::Version.create(Administrate::VERSION) >= Gem::Version.create("0.15.0")) ? "_page" : "page"
8
8
 
9
9
  class Engine < ::Rails::Engine
10
10
  end
metadata CHANGED
@@ -1,72 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: administrate_exportable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jônatas Rancan
8
8
  - Andrei Bondarev
9
- autorequire:
10
9
  bindir: exe
11
10
  cert_chain: []
12
- date: 2023-02-08 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
13
12
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: bundler
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - "~>"
19
- - !ruby/object:Gem::Version
20
- version: '1.16'
21
- type: :development
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - "~>"
26
- - !ruby/object:Gem::Version
27
- version: '1.16'
28
- - !ruby/object:Gem::Dependency
29
- name: rake
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - "~>"
33
- - !ruby/object:Gem::Version
34
- version: '10.0'
35
- type: :development
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - "~>"
40
- - !ruby/object:Gem::Version
41
- version: '10.0'
42
- - !ruby/object:Gem::Dependency
43
- name: rspec
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - "~>"
47
- - !ruby/object:Gem::Version
48
- version: '3.0'
49
- type: :development
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - "~>"
54
- - !ruby/object:Gem::Version
55
- version: '3.0'
56
- - !ruby/object:Gem::Dependency
57
- name: pry-byebug
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - "~>"
61
- - !ruby/object:Gem::Version
62
- version: '3.0'
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: '3.0'
70
13
  - !ruby/object:Gem::Dependency
71
14
  name: administrate
72
15
  requirement: !ruby/object:Gem::Requirement
@@ -123,6 +66,20 @@ dependencies:
123
66
  - - ">="
124
67
  - !ruby/object:Gem::Version
125
68
  version: 5.2.2.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: csv
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
126
83
  description: Simple plugin to add CSV export feature to Administrate
127
84
  email:
128
85
  - hello@sourcelabs.io
@@ -130,10 +87,10 @@ executables: []
130
87
  extensions: []
131
88
  extra_rdoc_files: []
132
89
  files:
90
+ - ".github/workflows/ci.yml"
133
91
  - ".gitignore"
134
92
  - ".rspec"
135
93
  - ".tool-versions"
136
- - ".travis.yml"
137
94
  - Gemfile
138
95
  - Gemfile.lock
139
96
  - LICENSE.txt
@@ -151,8 +108,9 @@ files:
151
108
  homepage: https://github.com/SourceLabsLLC/administrate_exportable
152
109
  licenses:
153
110
  - MIT
154
- metadata: {}
155
- post_install_message:
111
+ metadata:
112
+ source_code_uri: https://github.com/SourceLabsLLC/administrate_exportable
113
+ bug_tracker_uri: https://github.com/SourceLabsLLC/administrate_exportable/issues
156
114
  rdoc_options: []
157
115
  require_paths:
158
116
  - lib
@@ -167,8 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
125
  - !ruby/object:Gem::Version
168
126
  version: '0'
169
127
  requirements: []
170
- rubygems_version: 3.1.4
171
- signing_key:
128
+ rubygems_version: 4.0.3
172
129
  specification_version: 4
173
130
  summary: Simple plugin to add CSV export feature to Administrate
174
131
  test_files: []
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.4.2
5
- before_install: gem install bundler -v 1.16.0