Class: SpeakyCsv::ActiveRecordImport
- Inherits:
-
Object
- Object
- SpeakyCsv::ActiveRecordImport
- Includes:
- Enumerable
- Defined in:
- lib/speaky_csv/active_record_import.rb
Overview
Imports a csv file as unsaved active record instances
Constant Summary collapse
- QUERY_BATCH_SIZE =
20- TRUE_VALUES =
ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(config, input_io_or_enumerable, klass) ⇒ ActiveRecordImport
constructor
A new instance of ActiveRecordImport.
-
#log ⇒ Object
Returns a string of all the log output from the import.
Constructor Details
#initialize(config, input_io_or_enumerable, klass) ⇒ ActiveRecordImport
Returns a new instance of ActiveRecordImport.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/speaky_csv/active_record_import.rb', line 15 def initialize(config, input_io_or_enumerable, klass) @config = config @klass = klass @log_output = StringIO.new @logger = Logger.new @log_output if duck_type_is_io?(input_io_or_enumerable) @rx = AttrImport.new @config, input_io_or_enumerable @rx.logger = @logger else @rx = input_io_or_enumerable end end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
13 14 15 |
# File 'lib/speaky_csv/active_record_import.rb', line 13 def logger @logger end |
Instance Method Details
#each ⇒ Object
30 31 32 |
# File 'lib/speaky_csv/active_record_import.rb', line 30 def each block_given? ? enumerator.each { |a| yield a } : enumerator end |
#log ⇒ Object
Returns a string of all the log output from the import. Or returns nothing if a custom logger was used.
36 37 38 |
# File 'lib/speaky_csv/active_record_import.rb', line 36 def log @log_output.string end |