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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d96a573783d5a7e984d87ec08a3523e6c6586467
4
- data.tar.gz: 986d9649720710ddc899a677027320c8abd6439c
3
+ metadata.gz: a27f64330b23e828ecb9d05f2cdd49025ea0c9d4
4
+ data.tar.gz: d81cb5038d1ec1010533550bfec9d468bcffac8e
5
5
  SHA512:
6
- metadata.gz: bf08a457378d5be9bf935a7c5d835e2db9c7225a707e6ba2a5f18204a36d63435b56db6b43b0a8928f2607627406d9015990330f07e5e21fb6b52dca2258c54f
7
- data.tar.gz: cb268b269f89014522ea46e2105e84c2cda424b2d5eadecb2f907b52e6c8c7cb285f2e21231543980cea8f916ce02ba9b6cd47cc96c507c4ffb4ead272c1b89b
6
+ metadata.gz: c113d73e072c1cfffc042c11fb6b8b1e3312ca09f990ebf6bf9776a30eba5627c384e0ad412c7f7b23b96c49380b433468d43616ce7659240c13501a7182d4f9
7
+ data.tar.gz: 203f64c80b8def0e65a170c4656fd4d9ac7d0e96e0ba9397b72ac4ceab1afdc9842e1615bc7f33e1bee00e3ebc729e4ac148131c29e9146d51d2b446c9c70b2e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # CHANGELOG
2
2
 
3
+ ### Version 0.2.0
4
+ * Using I18n translations in file headers.
5
+
3
6
  ### Version 0.1.0
4
7
  * Including file headers
5
8
 
data/Gemfile CHANGED
@@ -3,3 +3,4 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
  gem 'coveralls', require: false
5
5
  gem 'rails'
6
+ gem 'sqlite3'
data/README.md CHANGED
@@ -130,6 +130,8 @@ end
130
130
  ```
131
131
  Rejected attributes will be blank in the downloaded file.
132
132
 
133
+ ### Headers
134
+ `ActiveModel::Exporters` uses I18n translations in file headers.
133
135
 
134
136
  ## Contributing
135
137
 
@@ -33,7 +33,14 @@ module ActiveModel
33
33
  end
34
34
 
35
35
  def headers
36
- exporter_for(collection.first).class._attributes
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
@@ -1,5 +1,5 @@
1
1
  module ActiveModel
2
2
  class Exporter
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -0,0 +1,3 @@
1
+ class ARUserExporter < ActiveModel::Exporter
2
+ attributes :first_name, :last_name
3
+ 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.1.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-10 00:00:00.000000000 Z
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