Class: DataImport::Importer
- Inherits:
-
Object
- Object
- DataImport::Importer
- Defined in:
- lib/data-import/importer.rb
Instance Method Summary collapse
-
#initialize(context, definition) ⇒ Importer
constructor
A new instance of Importer.
- #run ⇒ Object
Constructor Details
#initialize(context, definition) ⇒ Importer
Returns a new instance of Importer.
4 5 6 7 |
# File 'lib/data-import/importer.rb', line 4 def initialize(context, definition) @context = context @definition = definition end |
Instance Method Details
#run ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/data-import/importer.rb', line 9 def run @definition.target_database.transaction do = {} [:primary_key] = @definition.source_primary_key [:columns] = @definition.source_columns [:distinct] = @definition.source_distinct_columns [:order] = @definition.source_order_columns @definition.source_database.each_row(@definition.source_table_name, ) do |row| @context.before_filter.call(row) if @context.before_filter import_row row yield if block_given? end end @definition.after_blocks.each do |block| @definition.instance_exec(@context, &block) end end |