Class: ARCSVImporter::Importer
- Inherits:
-
Object
- Object
- ARCSVImporter::Importer
- Defined in:
- lib/ar_csv_importer/importer.rb
Instance Attribute Summary collapse
-
#file_path ⇒ Object
Returns the value of attribute file_path.
-
#import_class ⇒ Object
Returns the value of attribute import_class.
-
#row_order ⇒ Object
Returns the value of attribute row_order.
Instance Method Summary collapse
- #import(raise_validation_errors = false) ⇒ Object
-
#initialize(file_path, import_class, *row_order) ⇒ Importer
constructor
A new instance of Importer.
Constructor Details
#initialize(file_path, import_class, *row_order) ⇒ Importer
Returns a new instance of Importer.
5 6 7 8 9 |
# File 'lib/ar_csv_importer/importer.rb', line 5 def initialize(file_path, import_class, *row_order) @file_path = file_path @import_class = import_class @row_order = row_order.flatten end |
Instance Attribute Details
#file_path ⇒ Object
Returns the value of attribute file_path.
3 4 5 |
# File 'lib/ar_csv_importer/importer.rb', line 3 def file_path @file_path end |
#import_class ⇒ Object
Returns the value of attribute import_class.
3 4 5 |
# File 'lib/ar_csv_importer/importer.rb', line 3 def import_class @import_class end |
#row_order ⇒ Object
Returns the value of attribute row_order.
3 4 5 |
# File 'lib/ar_csv_importer/importer.rb', line 3 def row_order @row_order end |
Instance Method Details
#import(raise_validation_errors = false) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/ar_csv_importer/importer.rb', line 11 def import(raise_validation_errors = false) meth = raise_validation_errors ? :create! : :create CSV.foreach(file_path) do |row| import_class.send(meth, attrs_from_row(row)) end end |