Class: Impex::Engine
- Inherits:
-
Object
- Object
- Impex::Engine
- Defined in:
- lib/impex/engine.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Engine
constructor
A new instance of Engine.
- #run(&block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Engine
Returns a new instance of Engine.
3 4 |
# File 'lib/impex/engine.rb', line 3 def initialize( = {}) end |
Class Method Details
Instance Method Details
#run(&block) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/impex/engine.rb', line 6 def run(&block) @config = Impex.config @lookup = Impex::Lookup.new(@config) @files_loader = @lookup.file_loader @history_manager = @lookup.history_manager @files = @files_loader.load @files.each do |file| model = file.table file.each do |row| # the user can re-organize each row before saving. row = block.call(row) if block row = @history_manager.filter_data_with_history(row) reference_column = @config[:history_references][row.table.to_sym] || "reference" reference = row.columns[reference_column.to_s] record = model.find_or_initialize_by(reference_column => reference) insert_row(record, row.columns.except([reference_column])) @history_manager.update_history(row) end end end |