Skip to content

Commit 7f22be0

Browse files
committed
3.0.0.pre
2 parents 554e359 + e1f473f commit 7f22be0

30 files changed

+735
-148
lines changed

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
script: bundle exec rspec spec
2+
rvm:
3+
- 1.9.3
4+
- 2.0.0
5+
before_install:
6+
- gem update --system
7+
- gem --version

Gemfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,19 @@ source 'https://rubygems.org'
22

33
# Specify your gem's dependencies in active_admin_importable.gemspec
44
gemspec
5+
group :test do
6+
gem 'rails', '4.1.9'
7+
gem 'rspec-rails'
8+
gem 'activeadmin', github: 'activeadmin' , ref: '54bede0558a99ab759f98f9b24e1b0144063a81e'
9+
10+
gem 'coveralls', require: false # Test coverage website. Go to https://coveralls.io
11+
12+
gem 'devise'
13+
gem 'sass-rails'
14+
gem 'sqlite3'
15+
gem 'launchy'
16+
gem 'database_cleaner'
17+
gem 'capybara'
18+
gem 'selenium-webdriver'
19+
gem 'poltergeist'
20+
end

README.md

Lines changed: 104 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ The most fastest and efficient CSV import for Active Admin (based on activerecor
33
with support of validations and bulk inserts
44

55

6-
Should work with both AA 0.6 and 1.0.0
6+
7+
[![Build Status](http://img.shields.io/travis/Fivell/active_admin_import.svg)](https://travis-ci.org/Fivell/active_admin_import)
8+
[![Dependency Status](http://img.shields.io/gemnasium/Fivell/active_admin_import.svg)](https://gemnasium.com/Fivell/active_admin_import)
9+
[![Coverage Status](https://coveralls.io/repos/Fivell/active_admin_import/badge.svg?branch=3.0.0)](https://coveralls.io/r/Fivell/active_admin_import?branch=3.0.0)
10+
11+
branch for AA 1.0.0 and Rails >= 4.1
712

813

914
#Installation
@@ -12,60 +17,78 @@ Add this line to your application's Gemfile:
1217

1318
```ruby
1419
gem "active_admin_import" , '2.1.2'
15-
```
16-
17-
And then execute:
18-
19-
$ bundle
2020

21+
```
22+
or
2123

24+
```ruby
25+
gem "active_admin_import" , github: "Fivell/active_admin_import"
2226

23-
Why yet another import for ActiveAdmin ? Now with activerecord-import ....
27+
```
2428

25-
"Because plain-vanilla, out-of-the-box ActiveRecord doesn’t provide support for inserting large amounts of data efficiently"
29+
And then execute:
2630

27-
cool features of activerecord-import
31+
$ bundle
2832

29-
activerecord-import can perform validations (fast)
30-
activerecord-import can perform on duplicate key updates (requires mysql)
3133

3234

33-
So active_admin_import features
35+
#Why yet another import for ActiveAdmin ? Now with activerecord-import ....
3436

35-
Encoding handling
36-
Two step importing (see example2)
37-
CSV options
38-
Ability to prepend CSV headers automatically
39-
Bulk import (activerecord-import)
40-
Ability to customize template
41-
Callbacks support
42-
Zip files import
43-
and more ....
37+
<p>Because plain-vanilla, out-of-the-box ActiveRecord doesn’t provide support for inserting large amounts of data efficiently</p>
4438

45-
Options
39+
Features of activerecord-import
4640

47-
# +back+:: resource action to redirect after processing
48-
# +csv_options+:: hash with column separator, row separator, etc
49-
# +validate+:: true|false, means perfoem validations or not
50-
# +batch_size+:: integer value of max record count inserted by 1 query/transaction
51-
# +before_import+:: proc for before import action, hook called with importer object
52-
# +after_import+:: proc for after import action, hook called with importer object
53-
# +before_batch_import+:: proc for before each batch action, called with importer object
54-
# +after_batch_import+:: proc for after each batch action, called with importer object
55-
# +on_duplicate_key_update+:: an Array or Hash, tells activerecord-import to use MySQL's ON DUPLICATE KEY UPDATE ability.
56-
# +timestamps+:: true|false, tells activerecord-import to not add timestamps (if false) even if record timestamps is disabled in ActiveRecord::Base
57-
# +ignore+:: true|false, tells activerecord-import toto use MySQL's INSERT IGNORE ability
58-
# +params_keys+:: params values available in callbacks
59-
# +template+:: custom template rendering
60-
# +template_object+:: object passing to view
61-
# +locals+:: local variables for template
62-
# +resource_class+:: resource class name
63-
# +resource_label+:: resource label value
64-
# +headers_rewrites+:: hash with key (csv header) - value (db column name) rows mapping
41+
<ol>
42+
<li>activerecord-import can perform validations (fast)</li>
43+
<li>activerecord-import can perform on duplicate key updates (requires mysql)</li>
44+
</ol>
6545

46+
47+
6648

6749

68-
Default options values
50+
# active_admin_import features
51+
<ol>
52+
<li>Encoding handling</li>
53+
<li>Preview before importing (Example 2)</li>
54+
<li> CSV options</li>
55+
<li> Ability to prepend CSV headers automatically</li>
56+
<li>Bulk import (activerecord-import)</li>
57+
<li>Callbacks</li>
58+
<li>Zip files</li>
59+
<li>more...</li>
60+
</ol>
61+
62+
63+
64+
65+
#### Options
66+
67+
<table>
68+
<tr><td>name</td><td>description</td></tr>
69+
<tr><td>:back</td><td>resource action to redirect after processing</td></tr>
70+
<tr><td>:csv_options</td><td>hash with column separator, row separator, etc </td></tr>
71+
<tr><td>:validate</td><td>true|false, means perform validations or not</td></tr>
72+
<tr><td>:batch_size</td><td>integer value of max record count inserted by 1 query/transaction</td></tr>
73+
<tr><td>:before_import</td><td>proc for before import action, hook called with importer object</td></tr>
74+
<tr><td>:after_import</td><td>proc for after import action, hook called with importer object</td></tr>
75+
<tr><td>:before_batch_import</td><td>proc for before each batch action, called with importer object</td></tr>
76+
<tr><td>:after_batch_import</td><td>proc for after each batch action, called with importer object</td></tr>
77+
<tr><td>:on_duplicate_key_update</td><td>an Array or Hash, tells activerecord-import to use MySQL's ON DUPLICATE KEY UPDATE ability.</td></tr>
78+
<tr><td>:timestamps</td><td>true|false, tells activerecord-import to not add timestamps (if false) even if record timestamps is disabled in ActiveRecord::Base</td></tr>
79+
<tr><td>:ignore</td><td>true|false, tells activerecord-import toto use MySQL's INSERT IGNORE ability</td></tr>
80+
<tr><td>:template</td><td>custom template rendering</td></tr>
81+
<tr><td>:template_object</td><td>object passing to view</td></tr>
82+
<tr><td>:locals</td><td>more variables for template</td></tr>
83+
<tr><td>:resource_class</td><td>resource class name</td></tr>
84+
<tr><td>:resource_label</td><td>resource label value</td></tr>
85+
<tr><td>:plural_resource_label</td><td>pluralized resource label value (default config.plural_resource_label)</td></tr>
86+
<tr><td>:headers_rewrites</td><td>hash with key (csv header) - value (db column name) rows mapping</td></tr>
87+
</table>
88+
89+
90+
91+
#### Default options values
6992

7093
```ruby
7194
back: {action: :import},
@@ -77,75 +100,75 @@ Default options values
77100
plural_resource_label: config.plural_resource_label,
78101
```
79102

80-
Example1
103+
#### Example1
81104

82105
```ruby
83106
ActiveAdmin.register Post do
84-
active_admin_import :validate => false,
85-
:csv_options => {:col_sep => ";" },
86-
:before_import => proc{ Post.delete_all},
87-
:batch_size => 1000
107+
active_admin_import validate: false,
108+
csv_options: {col_sep: ";" },
109+
before_import: proc{ Post.delete_all},
110+
batch_size: 1000
88111

89112

90113
end
91114
```
92115

93116

94-
Example2 Importing to mediate table with insert select operation after import completion
117+
#### Example2 Importing to mediate table with insert select operation after import completion
95118

96-
This config allows to replace data without downtime
119+
<p> This config allows to replace data in 1 sql query with callback </p>
97120

98121
```ruby
99122
ActiveAdmin.register Post do
100-
active_admin_import :validate => false,
101-
:csv_options => {:col_sep => ";" },
102-
:resource_class => ImportedPost , # we import data into another resource
103-
:before_import => proc{ ImportedPost.delete_all },
104-
:after_import => proc{
123+
active_admin_import validate: false,
124+
csv_options: {col_sep: ";" },
125+
resource_class: ImportedPost , # we import data into another resource
126+
before_import: proc{ ImportedPost.delete_all },
127+
after_import: proc{
105128
Post.transaction do
106129
Post.delete_all
107-
Post.connection.execute("INSERT INTO posts (SELECT * FROM import_posts)")
130+
Post.connection.execute("INSERT INTO posts (SELECT * FROM imported_posts)")
108131
end
109132
},
110-
:back => proc { config.namespace.resource_for(Post).route_collection_path } # redirect to post index
133+
back: proc { config.namespace.resource_for(Post).route_collection_path } # redirect to post index
111134
end
112135
```
113136

114137

115-
Example3 Importing file without headers, but we always know file format, so we can predefine it
138+
#### Example3 Importing file without headers, but we always know file format, so we can predefine it
116139

117140
```ruby
118141
ActiveAdmin.register Post do
119-
active_admin_import :validate => true,
120-
:template_object => ActiveAdminImport::Model.new(
121-
:hint => "file will be imported with such header format: 'body','title','author'",
122-
:csv_headers => ["body","title","author"]
142+
active_admin_import validate: true,
143+
template_object: ActiveAdminImport::Model.new(
144+
hint: "file will be imported with such header format: 'body','title','author'",
145+
csv_headers: ["body","title","author"]
123146
)
124147
end
125148
```
126149

127-
Example4 Importing without forcing to UTF-8 and disallow archives
150+
#### Example4 Importing without forcing to UTF-8 and disallow archives
128151

129152

130153
```ruby
131154
ActiveAdmin.register Post do
132-
active_admin_import :validate => true,
133-
:template_object => ActiveAdminImport::Model.new(
134-
:hint => "file will be encoded to ISO-8859-1",
135-
:force_encoding => "ISO-8859-1",
136-
:allow_archive => false
155+
active_admin_import validate: true,
156+
template_object: ActiveAdminImport::Model.new(
157+
hint: "file will be encoded to ISO-8859-1",
158+
force_encoding: "ISO-8859-1",
159+
allow_archive: false
137160
)
138161
end
139162
```
140163

141164

142-
Example5 Callbacks for each bulk insert iteration
165+
#### Example5 Callbacks for each bulk insert iteration
143166

144167

145168
```ruby
146169
ActiveAdmin.register Post do
147-
active_admin_import :validate => true,
148-
:before_batch_import => proc { |import|
170+
active_admin_import validate: true,
171+
before_batch_import: proc { |import|
149172
import.file #current file used
150173
import.resource #ActiveRecord class to import to
151174
import.options # options
@@ -154,15 +177,15 @@ Example5 Callbacks for each bulk insert iteration
154177
import.csv_lines #lines to import
155178
import.model #template_object instance
156179
},
157-
:after_batch_import => proc{ |import|
180+
after_batch_import: proc{ |import|
158181
#the same
159182
}
160183
end
161184
```
162185

163-
Example6 dynamic CSV options, template overriding
186+
#### Example6 dynamic CSV options, template overriding
164187

165-
1) put overrided template to app/views/import.html.erb
188+
- put overrided template to ```app/views/import.html.erb```
166189

167190
```erb
168191
@@ -173,8 +196,8 @@ Example6 dynamic CSV options, template overriding
173196
<%= f.inputs do %>
174197
<%= f.input :file, as: :file %>
175198
<% end %>
176-
<%= f.inputs "CSV options", :for => [:csv_options, OpenStruct.new(@active_admin_import_model.csv_options)] do |csv| %>
177-
<% csv.with_options :input_html => {:style => 'width:40px;'} do |opts| %>
199+
<%= f.inputs "CSV options", for: [:csv_options, OpenStruct.new(@active_admin_import_model.csv_options)] do |csv| %>
200+
<% csv.with_options input_html: {style: 'width:40px;'} do |opts| %>
178201
<%= opts.input :col_sep %>
179202
<%= opts.input :row_sep %>
180203
<%= opts.input :quote_char %>
@@ -188,15 +211,15 @@ Example6 dynamic CSV options, template overriding
188211
189212
```
190213

191-
2) call method with following parameters
214+
- call method with following parameters
192215

193216
```ruby
194217
ActiveAdmin.register Post do
195-
active_admin_import :validate => false,
196-
:template => 'import' ,
197-
:template_object => ActiveAdminImport::Model.new(
198-
:hint => "specify CSV options"
199-
:csv_options => {:col_sep => ";", :row_sep => nil, :quote_char => nil}
218+
active_admin_import validate: false,
219+
template: 'import' ,
220+
template_object: ActiveAdminImport::Model.new(
221+
hint: "specify CSV options"
222+
csv_options: {col_sep: ";", row_sep nil, :quote_char => nil}
200223
)
201224
end
202225
```
@@ -206,8 +229,7 @@ https://github.com/gregbell/active_admin
206229

207230
https://github.com/zdennis/activerecord-import
208231

209-
#Source Doc
210-
http://rubydoc.info/gems/active_admin_import/2.1.1/
232+
211233

212234

213235

Rakefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
#!/usr/bin/env rake
2-
require "bundler/gem_tasks"
1+
require "bundler"
2+
require 'rake'
3+
Bundler.setup
4+
Bundler::GemHelper.install_tasks
5+
6+
# Import all our rake tasks
7+
FileList['tasks/**/*.rake'].each { |task| import task }

active_admin_import.gemspec

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ Gem::Specification.new do |gem|
1515
gem.require_paths = ["lib"]
1616
gem.version = ActiveAdminImport::VERSION
1717

18-
gem.add_runtime_dependency 'activerecord-import', '~> 0.4', '>= 0.4.1'
19-
gem.add_runtime_dependency 'activeadmin', '>= 0.6.0'
20-
gem.add_runtime_dependency 'rubyzip', '~> 1.0', '>= 1.0.0'
2118

19+
gem.add_runtime_dependency 'activerecord-import', '~> 0.7.0'
20+
21+
gem.add_runtime_dependency 'rubyzip', '~> 1.0', '>= 1.0.0'
22+
gem.add_dependency "rails", ">= 4.0"
2223

2324
end

config/locales/en.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ en:
22
active_admin:
33
import: "Import"
44
active_admin_import:
5+
file_error: "Error: %{message}"
56
file_format_error: "You can import only valid csv file"
67
file_empty_error: "You can't import empty file"
78
no_file_error: "Please, select file to import"
@@ -11,6 +12,6 @@ en:
1112
failed:
1213
one: "Failed to import 1 %{model}"
1314
other: "Failed to import %{count} %{plural_model}"
14-
import_model: "Import %{model}"
15+
import_model: "Import %{plural_model}"
1516
import_btn: "Import"
1617
import_btn_disabled: "Wait..."

config/locales/it.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ it:
22
active_admin:
33
import: "Importa"
44
active_admin_import:
5+
file_error: "Errore: %{message}"
56
file_format_error: "Puoi importare solo CSV conformi"
67
no_file_error: "Per favore, seleziona un file da importare"
78
file_empty_error: "Non è possibile importare file vuoto"
@@ -11,6 +12,6 @@ it:
1112
failed:
1213
one: "Importazione di 1 %{model} fallita"
1314
other: "Importazione di %{count} %{plural_model} fallita"
14-
import_model: "Importa %{model}"
15+
import_model: "Importa %{plural_model}"
1516
import_btn: "Importa"
1617
import_btn_disabled: "In attesa..."

lib/active_admin_import.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
require 'active_admin'
33
require 'active_admin_import/version'
44
require 'active_admin_import/engine'
5+
require 'active_admin_import/import_result'
6+
require 'active_admin_import/options'
57
require 'active_admin_import/dsl'
68
require 'active_admin_import/importer'
79
require 'active_admin_import/model'
810
require 'active_admin_import/authorization'
911
::ActiveAdmin::DSL.send(:include, ActiveAdminImport::DSL)
1012

13+

0 commit comments

Comments
 (0)