active_model_exporters 0.0.5 → 0.1.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
  SHA1:
3
- metadata.gz: 30a964ee00e6f0e49c06fafa36d234ecc9f0c830
4
- data.tar.gz: 4e4ccce791d424d0bc328a8233e3c7b71c624ad8
3
+ metadata.gz: d96a573783d5a7e984d87ec08a3523e6c6586467
4
+ data.tar.gz: 986d9649720710ddc899a677027320c8abd6439c
5
5
  SHA512:
6
- metadata.gz: d7343fe3ab75b28039cea63a2a46a2cb3c076427ab550c06305fb60a15366a82fd068d02f1d8f1e1c696449f4d3c30123fb83a7f44a560b1e227737e2d539363
7
- data.tar.gz: 059e57436e2e4d0fd1ac4fc9f1682d71c87660e5f20261ce192e6076328fd38fafb91082b20d605de7a82f03618eb242c8c20755cb5c531e4527d419861de1c3
6
+ metadata.gz: bf08a457378d5be9bf935a7c5d835e2db9c7225a707e6ba2a5f18204a36d63435b56db6b43b0a8928f2607627406d9015990330f07e5e21fb6b52dca2258c54f
7
+ data.tar.gz: cb268b269f89014522ea46e2105e84c2cda424b2d5eadecb2f907b52e6c8c7cb285f2e21231543980cea8f916ce02ba9b6cd47cc96c507c4ffb4ead272c1b89b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # CHANGELOG
2
2
 
3
+ ### Version 0.1.0
4
+ * Including file headers
5
+
3
6
  ### Version 0.0.5
4
7
  * Using send_data method
5
8
  * Customizable filename
@@ -16,19 +16,24 @@ module ActiveModel
16
16
  generate_file(col_sep: "\t")
17
17
  end
18
18
 
19
+ private
20
+
19
21
  def generate_file(options = {})
20
22
  CSV.generate(options) do |file|
23
+ file << headers
21
24
  collection.each do |object|
22
25
  file << exporter_for(object).values
23
26
  end
24
27
  end
25
28
  end
26
29
 
27
- private
28
-
29
30
  def exporter_for(object)
30
31
  exporter_class = exporter || Exporter.exporter_for(object)
31
32
  exporter_class.new(object, scope: scope)
32
33
  end
34
+
35
+ def headers
36
+ exporter_for(collection.first).class._attributes
37
+ end
33
38
  end
34
39
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveModel
2
2
  class Exporter
3
- VERSION = '0.0.5'
3
+ VERSION = '0.1.0'
4
4
  end
5
5
  end
@@ -39,12 +39,12 @@ module ActiveModel
39
39
  attributes.map { |attr| send(attr) if attrs.include?(attr) }
40
40
  end
41
41
 
42
+ private
43
+
42
44
  def filter(attrs)
43
45
  attrs
44
46
  end
45
47
 
46
- private
47
-
48
48
  def attributes
49
49
  self.class._attributes.dup
50
50
  end
@@ -18,7 +18,8 @@ module ActionController
18
18
  def test_render_using_implicit_exporter
19
19
  get :render_using_implicit_exporter
20
20
  assert_equal 'text/csv', @response.content_type
21
- assert_equal "Foo1,Bar1,Foo1-Bar1\n"\
21
+ assert_equal "first_name,last_name,full_name\n"\
22
+ "Foo1,Bar1,Foo1-Bar1\n"\
22
23
  "Foo2,Bar2,Foo2-Bar2\n"\
23
24
  "Foo3,Bar3,Foo3-Bar3\n", @response.body
24
25
  end
@@ -38,7 +39,8 @@ module ActionController
38
39
  def test_render_using_explicit_exporter
39
40
  get :render_using_explicit_exporter
40
41
  assert_equal 'text/csv', @response.content_type
41
- assert_equal "Foo1,Bar1\n", @response.body
42
+ assert_equal "first_name,last_name\n"\
43
+ "Foo1,Bar1\n", @response.body
42
44
  end
43
45
  end
44
46
 
@@ -62,7 +64,8 @@ module ActionController
62
64
  def test_render_using_implicit_exportation_scope
63
65
  get :render_using_implicit_exportation_scope
64
66
  assert_equal 'text/csv', @response.content_type
65
- assert_equal "Foo1,Bar1,Foo1-Bar1-current_user\n", @response.body
67
+ assert_equal "first_name,last_name,full_name\n"\
68
+ "Foo1,Bar1,Foo1-Bar1-current_user\n", @response.body
66
69
  end
67
70
  end
68
71
 
@@ -86,7 +89,8 @@ module ActionController
86
89
  def test_render_using_explicit_exportation_scope
87
90
  get :render_using_explicit_exportation_scope
88
91
  assert_equal 'text/csv', @response.content_type
89
- assert_equal "Foo1,Bar1,Foo1-Bar1-current_admin\n", @response.body
92
+ assert_equal "first_name,last_name,full_name\n"\
93
+ "Foo1,Bar1,Foo1-Bar1-current_admin\n", @response.body
90
94
  end
91
95
  end
92
96
 
@@ -112,7 +116,8 @@ module ActionController
112
116
  def test_render_calling_exportation_scope
113
117
  get :render_calling_exportation_scope
114
118
  assert_equal 'text/csv', @response.content_type
115
- assert_equal "Foo1,Bar1,Foo1-Bar1-current_admin\n", @response.body
119
+ assert_equal "first_name,last_name,full_name\n"\
120
+ "Foo1,Bar1,Foo1-Bar1-current_admin\n", @response.body
116
121
  end
117
122
  end
118
123
 
@@ -131,7 +136,8 @@ module ActionController
131
136
  def test_render_using_filter_attributes
132
137
  get :render_using_filter_attributes
133
138
  assert_equal 'text/csv', @response.content_type
134
- assert_equal "Foo1,,FooBar1\n"\
139
+ assert_equal "first_name,last_name,email\n"\
140
+ "Foo1,,FooBar1\n"\
135
141
  "Foo2,Bar2,FooBar2\n", @response.body
136
142
  end
137
143
  end
@@ -18,7 +18,8 @@ module ActionController
18
18
  def test_render_using_implicit_exporter
19
19
  get :render_using_implicit_exporter
20
20
  assert_equal 'application/vnd.ms-excel', @response.content_type
21
- assert_equal "Foo1\tBar1\tFoo1-Bar1\n"\
21
+ assert_equal "first_name\tlast_name\tfull_name\n"\
22
+ "Foo1\tBar1\tFoo1-Bar1\n"\
22
23
  "Foo2\tBar2\tFoo2-Bar2\n"\
23
24
  "Foo3\tBar3\tFoo3-Bar3\n", @response.body
24
25
  end
@@ -38,7 +39,8 @@ module ActionController
38
39
  def test_render_using_explicit_exporter
39
40
  get :render_using_explicit_exporter
40
41
  assert_equal 'application/vnd.ms-excel', @response.content_type
41
- assert_equal "Foo1\tBar1\n", @response.body
42
+ assert_equal "first_name\tlast_name\n"\
43
+ "Foo1\tBar1\n", @response.body
42
44
  end
43
45
  end
44
46
 
@@ -62,7 +64,8 @@ module ActionController
62
64
  def test_render_using_implicit_exportation_scope
63
65
  get :render_using_implicit_exportation_scope
64
66
  assert_equal 'application/vnd.ms-excel', @response.content_type
65
- assert_equal "Foo1\tBar1\tFoo1-Bar1-current_user\n", @response.body
67
+ assert_equal "first_name\tlast_name\tfull_name\n"\
68
+ "Foo1\tBar1\tFoo1-Bar1-current_user\n", @response.body
66
69
  end
67
70
  end
68
71
 
@@ -86,7 +89,8 @@ module ActionController
86
89
  def test_render_using_explicit_exportation_scope
87
90
  get :render_using_explicit_exportation_scope
88
91
  assert_equal 'application/vnd.ms-excel', @response.content_type
89
- assert_equal "Foo1\tBar1\tFoo1-Bar1-current_admin\n", @response.body
92
+ assert_equal "first_name\tlast_name\tfull_name\n"\
93
+ "Foo1\tBar1\tFoo1-Bar1-current_admin\n", @response.body
90
94
  end
91
95
  end
92
96
 
@@ -112,7 +116,8 @@ module ActionController
112
116
  def test_render_calling_exportation_scope
113
117
  get :render_calling_exportation_scope
114
118
  assert_equal 'application/vnd.ms-excel', @response.content_type
115
- assert_equal "Foo1\tBar1\tFoo1-Bar1-current_admin\n", @response.body
119
+ assert_equal "first_name\tlast_name\tfull_name\n"\
120
+ "Foo1\tBar1\tFoo1-Bar1-current_admin\n", @response.body
116
121
  end
117
122
  end
118
123
 
@@ -131,7 +136,8 @@ module ActionController
131
136
  def test_render_using_filter_attributes
132
137
  get :render_using_filter_attributes
133
138
  assert_equal 'application/vnd.ms-excel', @response.content_type
134
- assert_equal "Foo1\t\tFooBar1\n"\
139
+ assert_equal "first_name\tlast_name\temail\n"\
140
+ "Foo1\t\tFooBar1\n"\
135
141
  "Foo2\tBar2\tFooBar2\n", @response.body
136
142
  end
137
143
  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.0.5
4
+ version: 0.1.0
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: 2014-07-02 00:00:00.000000000 Z
11
+ date: 2014-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel