active_model_exporters 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile +1 -0
- data/README.md +2 -0
- data/lib/active_model/array_exporter.rb +8 -1
- data/lib/active_model/exporter/version.rb +1 -1
- data/test/fixtures/active_record/exporters.rb +3 -0
- data/test/fixtures/active_record/models.rb +17 -0
- data/test/fixtures/locale.rb +20 -0
- data/test/integration/active_record/exportation/csv_test.rb +23 -0
- data/test/test_helper.rb +3 -0
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a27f64330b23e828ecb9d05f2cdd49025ea0c9d4
|
4
|
+
data.tar.gz: d81cb5038d1ec1010533550bfec9d468bcffac8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c113d73e072c1cfffc042c11fb6b8b1e3312ca09f990ebf6bf9776a30eba5627c384e0ad412c7f7b23b96c49380b433468d43616ce7659240c13501a7182d4f9
|
7
|
+
data.tar.gz: 203f64c80b8def0e65a170c4656fd4d9ac7d0e96e0ba9397b72ac4ceab1afdc9842e1615bc7f33e1bee00e3ebc729e4ac148131c29e9146d51d2b446c9c70b2e
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -33,7 +33,14 @@ module ActiveModel
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def headers
|
36
|
-
|
36
|
+
object = collection.first
|
37
|
+
attributes = exporter_for(object).class._attributes.dup
|
38
|
+
|
39
|
+
if object.class.respond_to?(:human_attribute_name)
|
40
|
+
attributes.map { |attr| object.class.human_attribute_name(attr) }
|
41
|
+
else
|
42
|
+
attributes.map(&:to_s)
|
43
|
+
end
|
37
44
|
end
|
38
45
|
end
|
39
46
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
ActiveRecord::Base.establish_connection(
|
4
|
+
adapter: 'sqlite3',
|
5
|
+
database: ':memory:'
|
6
|
+
)
|
7
|
+
|
8
|
+
ActiveRecord::Schema.define do
|
9
|
+
create_table :ar_users, force: true do |t|
|
10
|
+
t.string :first_name
|
11
|
+
t.string :last_name
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class ARUser < ActiveRecord::Base
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'i18n'
|
2
|
+
|
3
|
+
class I18n::Backend::Simple
|
4
|
+
def translations_store
|
5
|
+
translations
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
I18n.enforce_available_locales = false
|
10
|
+
|
11
|
+
I18n.backend.translations_store[:en] = {
|
12
|
+
activerecord: {
|
13
|
+
attributes: {
|
14
|
+
ar_user: {
|
15
|
+
first_name: 'First',
|
16
|
+
last_name: 'Last'
|
17
|
+
}
|
18
|
+
}
|
19
|
+
}
|
20
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module ActiveModel
|
4
|
+
class Exporter::CSV
|
5
|
+
class LocaleHeadersTest < Minitest::Test
|
6
|
+
def setup
|
7
|
+
@collection = [
|
8
|
+
ARUser.new(first_name: 'ARFoo1', last_name: 'ARBar1'),
|
9
|
+
ARUser.new(first_name: 'ARFoo2', last_name: 'ARBar2'),
|
10
|
+
ARUser.new(first_name: 'ARFoo3', last_name: 'ARBar3')
|
11
|
+
]
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_locale_headers
|
15
|
+
exporter = ActiveModel::ArrayExporter.new(@collection)
|
16
|
+
assert_equal "First,Last\n"\
|
17
|
+
"ARFoo1,ARBar1\n"\
|
18
|
+
"ARFoo2,ARBar2\n"\
|
19
|
+
"ARFoo3,ARBar3\n", exporter.to_csv
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -4,8 +4,11 @@ require 'active_model_exporters'
|
|
4
4
|
require 'minitest/autorun'
|
5
5
|
require 'minitest/unit'
|
6
6
|
require 'minitest/pride'
|
7
|
+
require 'fixtures/locale'
|
7
8
|
require 'fixtures/models'
|
8
9
|
require 'fixtures/exporters'
|
10
|
+
require 'fixtures/active_record/models'
|
11
|
+
require 'fixtures/active_record/exporters'
|
9
12
|
|
10
13
|
module TestHelper
|
11
14
|
Routes = ActionDispatch::Routing::RouteSet.new
|
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.
|
4
|
+
version: 0.2.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-
|
11
|
+
date: 2014-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -61,10 +61,14 @@ files:
|
|
61
61
|
- lib/active_model/exporter/types.rb
|
62
62
|
- lib/active_model/exporter/version.rb
|
63
63
|
- lib/active_model_exporters.rb
|
64
|
+
- test/fixtures/active_record/exporters.rb
|
65
|
+
- test/fixtures/active_record/models.rb
|
64
66
|
- test/fixtures/exporters.rb
|
67
|
+
- test/fixtures/locale.rb
|
65
68
|
- test/fixtures/models.rb
|
66
69
|
- test/integration/action_controller/exportation/csv_test.rb
|
67
70
|
- test/integration/action_controller/exportation/xls_test.rb
|
71
|
+
- test/integration/active_record/exportation/csv_test.rb
|
68
72
|
- test/test_helper.rb
|
69
73
|
homepage: https://github.com/alejandrogutierrez/active_model_exporters
|
70
74
|
licenses:
|
@@ -91,8 +95,12 @@ signing_key:
|
|
91
95
|
specification_version: 4
|
92
96
|
summary: A simple way to export data in Rails.
|
93
97
|
test_files:
|
98
|
+
- test/fixtures/active_record/exporters.rb
|
99
|
+
- test/fixtures/active_record/models.rb
|
94
100
|
- test/fixtures/exporters.rb
|
101
|
+
- test/fixtures/locale.rb
|
95
102
|
- test/fixtures/models.rb
|
96
103
|
- test/integration/action_controller/exportation/csv_test.rb
|
97
104
|
- test/integration/action_controller/exportation/xls_test.rb
|
105
|
+
- test/integration/active_record/exportation/csv_test.rb
|
98
106
|
- test/test_helper.rb
|