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
-
#eager_load(options) ⇒ Object
Add eager_load options which will be used when querying records.
-
#includes(options) ⇒ Object
Add includes options which will be used when querying records.
-
#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.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/speaky_csv/active_record_import.rb', line 14 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.
12 13 14 |
# File 'lib/speaky_csv/active_record_import.rb', line 12 def logger @logger end |
Instance Method Details
#each ⇒ Object
29 30 31 |
# File 'lib/speaky_csv/active_record_import.rb', line 29 def each block_given? ? enumerator.each { |a| yield a } : enumerator end |
#eager_load(options) ⇒ Object
Add eager_load options which will be used when querying records.
48 49 50 |
# File 'lib/speaky_csv/active_record_import.rb', line 48 def eager_load() @eager_load = end |
#includes(options) ⇒ Object
Add includes options which will be used when querying records.
Useful to avoid N+1 type problems. Configured has_manys are automaticaly included and don’t need to be specified here.
43 44 45 |
# File 'lib/speaky_csv/active_record_import.rb', line 43 def includes() @includes = end |
#log ⇒ Object
Returns a string of all the log output from the import. Or returns nothing if a custom logger was used.
35 36 37 |
# File 'lib/speaky_csv/active_record_import.rb', line 35 def log @log_output.string end |