active_model_exporters 0.3.1 → 0.3.2
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 +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/action_controller/exportation.rb +1 -1
- data/lib/active_model/array_exporter.rb +2 -2
- data/lib/active_model/exporter/version.rb +1 -1
- data/lib/active_model/exporter.rb +2 -8
- data/test/integration/action_controller/exportation/csv_test.rb +17 -0
- data/test/integration/action_controller/exportation/xls_test.rb +17 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8b417030570553ee3ca6ad88db5394ac3873cce
|
4
|
+
data.tar.gz: 0ad3fc8b4af6103c65bc892d9e10c14f2e4dc57a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21ffb2988853f6d945f6d7522b78953ef4374d7d86ca2cb5f3c53e1819fa9c00187645970598aadf3f17ec2152882a83ebd617a3709e6f4dcf7eb2fa84fc4ce6
|
7
|
+
data.tar.gz: a55b6da7b9b0546af1e7214ff2d8fe1c44c621e139c22924790d408b31da08389f48e45036699da6f2caf2fb87e2db3ec85eb0859f2f426f9f73da635b3d2c50
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
### Version 0.3.2
|
4
|
+
* Adding support to export a single resource.
|
5
|
+
|
6
|
+
### Version 0.3.1
|
7
|
+
* Fixing errors with rails 4.2+.
|
8
|
+
|
9
|
+
### Version 0.3.0
|
10
|
+
* Adding support to rails 4.2+.
|
11
|
+
|
3
12
|
### Version 0.2.0
|
4
13
|
* Using I18n translations in file headers.
|
5
14
|
|
@@ -30,7 +30,7 @@ module ActionController
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def build_exporter(resource, options)
|
33
|
-
if exporter = ActiveModel::
|
33
|
+
if exporter = ActiveModel::ArrayExporter
|
34
34
|
options[:scope] ||= exportation_scope
|
35
35
|
exporter.new(resource, options)
|
36
36
|
end
|
@@ -3,7 +3,7 @@ module ActiveModel
|
|
3
3
|
attr_reader :collection, :exporter, :scope
|
4
4
|
|
5
5
|
def initialize(collection, options = {})
|
6
|
-
@collection = collection
|
6
|
+
@collection = Array(collection)
|
7
7
|
@scope = options.delete(:scope)
|
8
8
|
@exporter = options.delete(:exporter)
|
9
9
|
end
|
@@ -34,7 +34,7 @@ module ActiveModel
|
|
34
34
|
|
35
35
|
def headers
|
36
36
|
object = collection.first
|
37
|
-
attributes = exporter_for(object).
|
37
|
+
attributes = exporter_for(object).attributes
|
38
38
|
|
39
39
|
if object.class.respond_to?(:human_attribute_name)
|
40
40
|
attributes.map { |attr| object.class.human_attribute_name(attr) }
|
@@ -18,16 +18,12 @@ module ActiveModel
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def exporter_for(resource)
|
21
|
-
|
22
|
-
ArrayExporter
|
23
|
-
else
|
24
|
-
"#{resource.class.name}Exporter".safe_constantize
|
25
|
-
end
|
21
|
+
"#{resource.class.name}Exporter".safe_constantize
|
26
22
|
end
|
27
23
|
end
|
28
24
|
|
29
25
|
|
30
|
-
|
26
|
+
attr_reader :object, :scope
|
31
27
|
|
32
28
|
def initialize(object, options = {})
|
33
29
|
@object = object
|
@@ -39,8 +35,6 @@ module ActiveModel
|
|
39
35
|
attributes.map { |attr| send(attr) if attrs.include?(attr) }
|
40
36
|
end
|
41
37
|
|
42
|
-
private
|
43
|
-
|
44
38
|
def filter(attrs)
|
45
39
|
attrs
|
46
40
|
end
|
@@ -141,5 +141,22 @@ module ActionController
|
|
141
141
|
"Foo2,Bar2,FooBar2\n", @response.body
|
142
142
|
end
|
143
143
|
end
|
144
|
+
|
145
|
+
class ExporterSingleResourceTest < ActionController::TestCase
|
146
|
+
class TestsController < ActionController::Base
|
147
|
+
def render_single_resource
|
148
|
+
render csv: User.new(first_name: 'Foo1', last_name: 'Bar1')
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
tests TestsController
|
153
|
+
|
154
|
+
def test_render_single_resource
|
155
|
+
get :render_single_resource
|
156
|
+
assert_equal 'text/csv', @response.content_type
|
157
|
+
assert_equal "first_name,last_name,full_name\n"\
|
158
|
+
"Foo1,Bar1,Foo1-Bar1\n", @response.body
|
159
|
+
end
|
160
|
+
end
|
144
161
|
end
|
145
162
|
end
|
@@ -141,5 +141,22 @@ module ActionController
|
|
141
141
|
"Foo2\tBar2\tFooBar2\n", @response.body
|
142
142
|
end
|
143
143
|
end
|
144
|
+
|
145
|
+
class ExporterSingleResourceTest < ActionController::TestCase
|
146
|
+
class TestsController < ActionController::Base
|
147
|
+
def render_single_resource
|
148
|
+
render xls: User.new(first_name: 'Foo1', last_name: 'Bar1')
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
tests TestsController
|
153
|
+
|
154
|
+
def test_render_single_resource
|
155
|
+
get :render_single_resource
|
156
|
+
assert_equal 'application/vnd.ms-excel', @response.content_type
|
157
|
+
assert_equal "first_name\tlast_name\tfull_name\n"\
|
158
|
+
"Foo1\tBar1\tFoo1-Bar1\n", @response.body
|
159
|
+
end
|
160
|
+
end
|
144
161
|
end
|
145
162
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_model_exporters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alejandro Gutiérrez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|