module InstDataShipper module DataSources # This module contains the logic for processing local AR tables module LocalTables extend ActiveSupport::Concern public def import_local_table(*args, **kwargs) delayed(:_import_local_table, *args, **kwargs) end private def _import_local_table(table_name) table_def = table_schemas.find { |t| t[:model].to_s == table_name } model = table_def[:model] inner_block = ->(file) { query = model query = query.includes(table_def[:includes]) if table_def[:includes].present? model.find_each do |m| file << table_def[:columns].map do |c| c[:transformer].present? ? m.instance_exec(&c[:transformer]) : m[c[:local_name].to_s] end end } upload_data(table_def, &inner_block) end end end end