Sha256: 291259570f14d4e9e51a9c8295e179ffd2fbcc7a7312f595d5e7a9858bf9ac3e
Contents?: true
Size: 1.67 KB
Versions: 1
Compression:
Stored size: 1.67 KB
Contents
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(model, schema_name: nil) model = model.safe_constantize if model.is_a?(String) table_def = lookup_table_schema!(schema_name, { model: model }) inner_block = ->(file) { query = model.all query = _resolve_model_query(query, table_def[:query]) if table_is_incremental?(table_def) query = _resolve_model_query( query, table_def.dig(:incremental, :scope), string: ->(query, column) { query.where("#{column} > ?", incremental_since) }, default: "updated_at", ) end query.find_each do |m| file << table_def[:columns].map do |c| instance_exec(m, &c[:block]) end end } upload_data(table_def, &inner_block) end def _resolve_model_query(relation, query, string: nil, default: nil) return relation if query == false query = default if query.nil? return relation if query.nil? if query.is_a?(Symbol) relation.send(query) elsif query.is_a?(Proc) instance_exec(relation, &query) elsif query.is_a?(String) && string.present? instance_exec(relation, query, &string) else raise "Invalid query: #{query.inspect}" end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
inst_data_shipper-0.2.0 | lib/inst_data_shipper/data_sources/local_tables.rb |