Class: DataSource
- Inherits:
-
Object
- Object
- DataSource
- Defined in:
- lib/data_source.rb
Instance Attribute Summary collapse
-
#input_path ⇒ Object
readonly
Returns the value of attribute input_path.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
Instance Method Summary collapse
- #drop_table ⇒ Object
- #import ⇒ Object
-
#initialize(table_name, input_path, csv_opts = {}, &block) ⇒ DataSource
constructor
A new instance of DataSource.
- #table_exists? ⇒ Boolean
Constructor Details
#initialize(table_name, input_path, csv_opts = {}, &block) ⇒ DataSource
Returns a new instance of DataSource.
8 9 10 11 12 |
# File 'lib/data_source.rb', line 8 def initialize table_name, input_path, csv_opts = {}, &block @table_name, @input_path = table_name, input_path @csv_opts = csv_opts ? csv_opts.dup : {} @block = block end |
Instance Attribute Details
#input_path ⇒ Object (readonly)
Returns the value of attribute input_path.
6 7 8 |
# File 'lib/data_source.rb', line 6 def input_path @input_path end |
#table_name ⇒ Object (readonly)
Returns the value of attribute table_name.
6 7 8 |
# File 'lib/data_source.rb', line 6 def table_name @table_name end |
Instance Method Details
#drop_table ⇒ Object
29 30 31 |
# File 'lib/data_source.rb', line 29 def drop_table conn.drop_table table_name end |
#import ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/data_source.rb', line 14 def import batch = [] TableUtils::Progress.over csv do |row, | batch << common_columns.map{ |c| row[c] } if batch.count >= 1000 || .finished? model.import common_columns, batch, validate: false batch = [] end end end |
#table_exists? ⇒ Boolean
25 26 27 |
# File 'lib/data_source.rb', line 25 def table_exists? conn.table_exists? table_name end |