Skip to content

Commit d00758a

Browse files
author
Pair
committed
Add configurable error_limit option
-[x] Update README.md -[x] Whitelist new :error_limit option -[x] Set default :error_limit to 5 -[x] sends option[:error_limit] instead of hardcoded 5 from dsl -[x] import result checks for option[:error_limit]
1 parent 6eb7042 commit d00758a

File tree

4 files changed

+24
-29
lines changed

4 files changed

+24
-29
lines changed

README.md

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# ActiveAdminImport
1+
# ActiveAdminImport
22
[The most fastest and efficient CSV import for Active Admin
33
with support of validations, bulk inserts and encodings handling](http://activeadmin-plugins.github.io/active_admin_import/)
4-
4+
55

66

77
[![Build Status](https://img.shields.io/travis/activeadmin-plugins/active_admin_import.svg)](https://travis-ci.org/activeadmin-plugins/active_admin_import)
@@ -46,7 +46,7 @@ And then execute:
4646
<li> and more...</li>
4747
</ol>
4848

49-
49+
5050

5151
#### Basic usage
5252

@@ -60,24 +60,25 @@ end
6060
#### Options
6161
Tool | Description
6262
--------------------- | -----------
63-
:back |resource action to redirect after processing
64-
:csv_options |hash with column separator, row separator, etc
65-
:validate |bool means perform validations or not
66-
:batch_size |integer value of max record count inserted by 1 query/transaction
63+
:back |resource action to redirect after processing
64+
:csv_options |hash with column separator, row separator, etc
65+
:validate |bool means perform validations or not
66+
:batch_size |integer value of max record count inserted by 1 query/transaction
6767
:batch_transaction |bool (false by default), if transaction is used when batch importing and works when :validate is set to true
68-
:before_import |proc for before import action, hook called with importer object
69-
:after_import |proc for after import action, hook called with importer object
70-
:before_batch_import |proc for before each batch action, called with importer object
71-
:after_batch_import |proc for after each batch action, called with importer object
68+
:before_import |proc for before import action, hook called with importer object
69+
:after_import |proc for after import action, hook called with importer object
70+
:before_batch_import |proc for before each batch action, called with importer object
71+
:after_batch_import |proc for after each batch action, called with importer object
7272
:on_duplicate_key_update|an Array or Hash, tells activerecord-import to use MySQL's ON DUPLICATE KEY UPDATE or Postgres 9.5+ ON CONFLICT DO UPDATE ability.
73-
:timestamps |bool, tells activerecord-import to not add timestamps (if false) even if record timestamps is disabled in ActiveRecord::Base
74-
:ignore |bool, tells activerecord-import to use MySQL's INSERT IGNORE ability
75-
:template |custom template rendering
76-
:template_object |object passing to view
77-
:resource_class |resource class name
78-
:resource_label |resource label value
79-
:plural_resource_label |pluralized resource label value (default config.plural_resource_label)
80-
:headers_rewrites |hash with key (csv header) - value (db column name) rows mapping
73+
:timestamps |bool, tells activerecord-import to not add timestamps (if false) even if record timestamps is disabled in ActiveRecord::Base
74+
:ignore |bool, tells activerecord-import to use MySQL's INSERT IGNORE ability
75+
:template |custom template rendering
76+
:template_object |object passing to view
77+
:resource_class |resource class name
78+
:resource_label |resource label value
79+
:plural_resource_label |pluralized resource label value (default config.plural_resource_label)
80+
:error_limit |Limit the number of errors reported (default `5`, set to `nil` for all)
81+
:headers_rewrites |hash with key (csv header) - value (db column name) rows mapping
8182

8283

8384

@@ -103,11 +104,3 @@ Tool | Description
103104
3. Commit your changes (`git commit -am 'Add some feature'`)
104105
4. Push to the branch (`git push origin my-new-feature`)
105106
5. Create new Pull Request
106-
107-
108-
109-
110-
111-
112-
113-

lib/active_admin_import/dsl.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module DSL
3737
count: result.failed.count,
3838
model: model_name,
3939
plural_model: plural_model_name,
40-
message: result.failed_message(limit: 5))
40+
message: result.failed_message(limit: options[:error_limit]))
4141
return if options[:batch_transaction]
4242
end
4343
if result.imported?

lib/active_admin_import/import_result.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def empty?
3030
end
3131

3232
def failed_message(options = {})
33-
limit = options.fetch(:limit, failed.count)
33+
limit = options[:limit] || failed.count
3434
failed.first(limit).map do |record|
3535
errors = record.errors
3636
(errors.full_messages.zip errors.keys.map { |k| record.send k }).map { |ms| ms.join(' - ') }.join(', ')

lib/active_admin_import/options.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module Options
1919
:resource_class,
2020
:resource_label,
2121
:plural_resource_label,
22+
:error_limit,
2223
:headers_rewrites
2324
].freeze
2425

@@ -34,6 +35,7 @@ def self.options_for(config, options = {})
3435
resource_class: config.resource_class,
3536
resource_label: config.resource_label,
3637
plural_resource_label: config.plural_resource_label,
38+
error_limit: 5,
3739
headers_rewrites: {}
3840
}.deep_merge(options)
3941
end

0 commit comments

Comments
 (0)