Class: ActiveRecordJsonImporter::Importer
- Inherits:
-
Object
- Object
- ActiveRecordJsonImporter::Importer
- Defined in:
- lib/active_record_json_importer.rb
Constant Summary collapse
- RECORDS_AT_ONCE =
5000
Instance Attribute Summary collapse
-
#active_record_class ⇒ Object
readonly
Returns the value of attribute active_record_class.
-
#bulk_input_file ⇒ Object
readonly
Returns the value of attribute bulk_input_file.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#records_at_once ⇒ Object
Returns the value of attribute records_at_once.
Instance Method Summary collapse
- #import ⇒ Object
-
#initialize(options = {}) ⇒ Importer
constructor
A new instance of Importer.
Constructor Details
#initialize(options = {}) ⇒ Importer
Returns a new instance of Importer.
12 13 14 15 16 17 |
# File 'lib/active_record_json_importer.rb', line 12 def initialize( = {}) @options = initialize_active_record_class initialize_bulk_input_file initialize_records_at_once end |
Instance Attribute Details
#active_record_class ⇒ Object (readonly)
Returns the value of attribute active_record_class.
7 8 9 |
# File 'lib/active_record_json_importer.rb', line 7 def active_record_class @active_record_class end |
#bulk_input_file ⇒ Object (readonly)
Returns the value of attribute bulk_input_file.
7 8 9 |
# File 'lib/active_record_json_importer.rb', line 7 def bulk_input_file @bulk_input_file end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/active_record_json_importer.rb', line 7 def @options end |
#records_at_once ⇒ Object
Returns the value of attribute records_at_once.
8 9 10 |
# File 'lib/active_record_json_importer.rb', line 8 def records_at_once @records_at_once end |
Instance Method Details
#import ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/active_record_json_importer.rb', line 19 def import records = [] bulk_input_file.each_with_index do |line, index| records << JSON.parse(line) if (index % records_at_once == 0) import_records records records = [] end end bulk_input_file.close import_records records if records.any? return true end |