administrate_exportable 0.7.0 → 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: 66d0a1d7b10a17a14ff7c4553f751d34c756b1f1138614c15f1144b807e9161f
4
- data.tar.gz: e7669105bcb5d34ddfb92520a57f07eb9c28871510cc7aa28a7bbd21189818b3
3
+ metadata.gz: 9cbff1fff937f0640ccdb42b0f80363220ae4d91a8a4f98a22394c2481a3c86a
4
+ data.tar.gz: b54ba5b4180434920f8eddf45ea38b51371d51fef4a61336252c6560edf4c2be
5
5
  SHA512:
6
- metadata.gz: afd7af1c25b548fac0bea63635190d6ac3a98cc30622390db4f02535ea33b7b3494a4bf71d672845466ba6caa5bbbe92e21e2bc2e79a98d96a5ec83bfe745840
7
- data.tar.gz: 82b748cbd381e7890a2ce35a6f05029a4cab127c676f2c344237398734a59b499472ef863c417d3a7d835840ed3592f2a1ae1200dcfc604a9117727690a4ba2a
6
+ metadata.gz: aca50be90261668a6eeabd518cdb12846ffe35e68b61c1196164b352ffa9417295a757981950c66ae968254e1343e8fc00876de9190439f72e10bdbd16b74c0a
7
+ data.tar.gz: 0aa6961811d2dbd28b20af2a9d47bb0e713ce3e6b099b61a712ac2c9de89f5ce7a9e3cd5bdbf114ac7443a85b860711e221401be508775e61205dfca5e92abdd
@@ -12,10 +12,10 @@ jobs:
12
12
  runs-on: ubuntu-latest
13
13
  strategy:
14
14
  matrix:
15
- ruby: ["3.1", "3.2", "3.3", "3.4"]
15
+ ruby: ["3.2", "3.3", "3.4", "4.0"]
16
16
 
17
17
  steps:
18
- - uses: actions/checkout@master
18
+ - uses: actions/checkout@v7
19
19
 
20
20
  - name: Set up Ruby
21
21
  uses: ruby/setup-ruby@v1
@@ -33,11 +33,11 @@ jobs:
33
33
  docs:
34
34
  runs-on: ubuntu-latest
35
35
  steps:
36
- - uses: actions/checkout@master
36
+ - uses: actions/checkout@v7
37
37
  - name: Set up Ruby
38
38
  uses: ruby/setup-ruby@v1
39
39
  with:
40
- ruby-version: 3.3
40
+ ruby-version: "4.0"
41
41
  bundler: default
42
42
  bundler-cache: true
43
43
  - name: Build docs
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 3.1.6
1
+ ruby 4.0.0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- administrate_exportable (0.7.0)
4
+ administrate_exportable (0.8.0)
5
5
  actionview (>= 5.2.2.1)
6
6
  administrate (>= 0.17.0)
7
7
  csv (~> 3.0)
@@ -172,10 +172,10 @@ GEM
172
172
  net-smtp (0.5.1)
173
173
  net-protocol
174
174
  nio4r (2.7.5)
175
- nokogiri (1.18.10)
175
+ nokogiri (1.19.4)
176
176
  mini_portile2 (~> 2.8.2)
177
177
  racc (~> 1.4)
178
- nokogiri (1.18.10-arm64-darwin)
178
+ nokogiri (1.19.4-arm64-darwin)
179
179
  racc (~> 1.4)
180
180
  parallel (1.27.0)
181
181
  parser (3.3.10.1)
@@ -298,9 +298,9 @@ GEM
298
298
  actionpack (>= 6.1)
299
299
  activesupport (>= 6.1)
300
300
  sprockets (>= 3.0.0)
301
- sqlite3 (2.8.1)
301
+ sqlite3 (2.10.1)
302
302
  mini_portile2 (~> 2.8.0)
303
- sqlite3 (2.8.1-arm64-darwin)
303
+ sqlite3 (2.10.1-arm64-darwin)
304
304
  standard (1.53.0)
305
305
  language_server-protocol (~> 3.17.0.2)
306
306
  lint_roller (~> 1.0)
data/README.md CHANGED
@@ -63,7 +63,7 @@ ATTRIBUTE_TYPES = {
63
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
64
 
65
65
  ```ruby
66
- 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 existing_action?(resource_class, :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)
67
67
  ```
68
68
 
69
69
  Example:
@@ -82,13 +82,31 @@ Example:
82
82
 
83
83
  <%= link_to(
84
84
  'Export',
85
- [:export, namespace.to_sym, page.resource_name.to_s.pluralize.to_sym, sanitized_order_params(page, :id).to_h.merge(format: :csv)],
86
- class: 'button'
87
- ) if existing_action?(resource_class, :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) %>
88
90
  </div>
89
91
  ....
90
92
  ```
91
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
+
92
110
  ### Using with Pundit
93
111
 
94
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.
@@ -12,14 +12,8 @@ Gem::Specification.new do |spec|
12
12
  spec.description = spec.summary
13
13
  spec.license = "MIT"
14
14
 
15
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
16
- # to allow pushing to a single host or delete this section to allow pushing to any host.
17
- # if spec.respond_to?(:metadata)
18
- # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
19
- # else
20
- # raise "RubyGems 2.0 or newer is required to protect against " \
21
- # "public gem pushes."
22
- # end
15
+ spec.metadata["source_code_uri"] = spec.homepage
16
+ spec.metadata["bug_tracker_uri"] = "#{spec.homepage}/issues"
23
17
 
24
18
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
25
19
  f.match(%r{^(test|spec|features)/})
@@ -28,10 +22,6 @@ Gem::Specification.new do |spec|
28
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
23
  spec.require_paths = ["lib"]
30
24
 
31
- spec.add_development_dependency "bundler", "~> 1.16"
32
- spec.add_development_dependency "rake", "~> 10.0"
33
- spec.add_development_dependency "rspec", "~> 3.0"
34
- spec.add_development_dependency "pry-byebug", "~> 3.0"
35
25
  spec.add_dependency "administrate", ">= 0.17.0"
36
26
  spec.add_dependency "rails", ">= 4.2"
37
27
  spec.add_dependency "actionview", ">= 5.2.2.1"
@@ -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'
32
+ target: '_blank',
33
+ data: { turbolinks: false, turbo: false }
33
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
 
@@ -7,7 +7,7 @@ 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
@@ -40,7 +40,7 @@ module AdministrateExportable
40
40
  when Administrate::Field::BelongsTo.to_s, Administrate::Field::HasOne.to_s, Administrate::Field::Polymorphic.to_s
41
41
  field.display_associated_resource if field.data
42
42
  when Administrate::Field::HasMany.to_s
43
- field.data&.count
43
+ field.data&.size
44
44
  when Administrate::Field::DateTime.to_s
45
45
  field.datetime if field.data
46
46
  when Administrate::Field::Date.to_s
@@ -72,7 +72,7 @@ module AdministrateExportable
72
72
  end
73
73
 
74
74
  def attributes_to_export
75
- @attributes_to_export ||= dashboard.class::ATTRIBUTE_TYPES.select do |attribute_key, attribute_type|
75
+ @attributes_to_export ||= dashboard.attribute_types.select do |attribute_key, attribute_type|
76
76
  attribute_options = attribute_type.try(:options)
77
77
 
78
78
  !attribute_options || attribute_options[:export] != false
@@ -80,7 +80,18 @@ module AdministrateExportable
80
80
  end
81
81
 
82
82
  def collection
83
- 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
84
95
  end
85
96
  end
86
97
  end
@@ -1,3 +1,3 @@
1
1
  module AdministrateExportable
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.0"
3
3
  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.7.0
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: 2026-03-05 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
@@ -148,7 +91,6 @@ files:
148
91
  - ".gitignore"
149
92
  - ".rspec"
150
93
  - ".tool-versions"
151
- - ".travis.yml"
152
94
  - Gemfile
153
95
  - Gemfile.lock
154
96
  - LICENSE.txt
@@ -166,8 +108,9 @@ files:
166
108
  homepage: https://github.com/SourceLabsLLC/administrate_exportable
167
109
  licenses:
168
110
  - MIT
169
- metadata: {}
170
- 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
171
114
  rdoc_options: []
172
115
  require_paths:
173
116
  - lib
@@ -182,8 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
125
  - !ruby/object:Gem::Version
183
126
  version: '0'
184
127
  requirements: []
185
- rubygems_version: 3.3.27
186
- signing_key:
128
+ rubygems_version: 4.0.3
187
129
  specification_version: 4
188
130
  summary: Simple plugin to add CSV export feature to Administrate
189
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