Class: Para::Importer::Base
- Defined in:
- lib/para/importer/base.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#sheet ⇒ Object
readonly
Returns the value of attribute sheet.
Instance Method Summary collapse
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
6 7 8 |
# File 'lib/para/importer/base.rb', line 6 def file @file end |
#sheet ⇒ Object (readonly)
Returns the value of attribute sheet.
6 7 8 |
# File 'lib/para/importer/base.rb', line 6 def sheet @sheet end |
Instance Method Details
#perform(file, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/para/importer/base.rb', line 8 def perform(file, = {}) @file = file .reverse_merge!(extension: file.) @sheet = Roo::Spreadsheet.open(file., ) ActiveRecord::Base.transaction do (2..(sheet.last_row)).each do |index| begin progress! import_from_row(sheet.row(index)) rescue ActiveRecord::RecordInvalid => error if allows_import_errors? add_errors_from(index, error.record) else raise end end end end save_errors! # Ensure that `.perform_now` returns the importer self end |