diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/models/simple_importer.rb | 16 | ||||
| -rw-r--r-- | app/models/simple_interface.rb | 7 | ||||
| -rw-r--r-- | app/models/simple_interfaces_group.rb | 4 |
3 files changed, 17 insertions, 10 deletions
diff --git a/app/models/simple_importer.rb b/app/models/simple_importer.rb index 4cfe90cff..d47ff6a92 100644 --- a/app/models/simple_importer.rb +++ b/app/models/simple_importer.rb @@ -42,8 +42,10 @@ class SimpleImporter < SimpleInterface end def dump_csv_from_context - dir = context[:logs_output_dir] || "log/importers" - filepath = File.join dir, "#{self.configuration_name}_#{Time.now.strftime "%y%m%d%H%M"}.csv" + dir = @output_dir + FileUtils.mkdir_p dir + + filepath = File.join dir, "#{self.configuration_name}_#{Time.now.strftime "%y%m%d%H%M"}_dump.csv" # for some reason, context[:csv].to_csv does not work CSV.open(filepath, 'w') do |csv| header = true @@ -131,14 +133,16 @@ class SimpleImporter < SimpleInterface @current_attribute = col[:attribute] val = col[:value] if val.nil? || val.is_a?(Proc) - if row.has_key? col.name - if val.is_a?(Proc) + if val.is_a?(Proc) + if row.has_key? col.name val = instance_exec(row[col.name], &val) else - val = row[col.name] + val = instance_exec(&val) end + elsif row.has_key? col.name + val = row[col.name] else - push_in_journal({event: :column_not_found, message: "Column not found: #{col.name}", kind: :warning}) + push_in_journal({event: :column_not_found, message: "Column not found: #{col.name || col.attribute}", kind: :warning}) self.status ||= :success_with_warnings end end diff --git a/app/models/simple_interface.rb b/app/models/simple_interface.rb index 43c740b57..561f241ae 100644 --- a/app/models/simple_interface.rb +++ b/app/models/simple_interface.rb @@ -97,13 +97,14 @@ class SimpleInterface < ActiveRecord::Base def write_output_to_csv cols = %i(line kind event message error) - if self.journal.size > 0 && self.journal.first[:row].present? + journal = self.journal && self.journal.map(&:symbolize_keys) + if journal && journal.size > 0 && journal.first[:row].present? log "Writing output log" FileUtils.mkdir_p @output_dir - keys = self.journal.first[:row].map(&:first) + keys = journal.first[:row].map(&:first) CSV.open(output_filepath, "w") do |csv| csv << cols + keys - self.journal.each do |j| + journal.each do |j| csv << cols.map{|c| j[c]} + j[:row].map(&:last) end end diff --git a/app/models/simple_interfaces_group.rb b/app/models/simple_interfaces_group.rb index 808be6570..53e28c36a 100644 --- a/app/models/simple_interfaces_group.rb +++ b/app/models/simple_interfaces_group.rb @@ -30,7 +30,9 @@ class SimpleInterfacesGroup name = "### #{self.name} ###" centered_name = " " * ([width - name.size, 0].max / 2) + name - banner = [centered_name, ""] + banner = [centered_name] + banner << "Output to: #{shared_options[:output_dir]}" if shared_options[:output_dir] + banner << "" banner << @interfaces.each_with_index.map do |interface, i| if interface[:interface].status.present? SimpleInterface.colorize interface[:name], SimpleInterface.status_color(interface[:interface].status) |
