Sha256: 92da34fdb7ee0e11891409bc5e8683e9fc939d38a36a557f1923142b40a40625

Contents?: true

Size: 1.6 KB

Versions: 3

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

require "logger"

module DataTaster
  autoload :Collection, "data_taster/collection"
  autoload :Confection, "data_taster/confection"
  autoload :Detergent, "data_taster/detergent"
  autoload :Helper, "data_taster/helper"
  autoload :Sample, "data_taster/sample"
  autoload :Sanitizer, "data_taster/sanitizer"

  SKIP_CODE = "skip_processing"

  def self.logger=(logger)
    @logger = logger
  end

  def self.logger
    @logger ||= Logger.new($stdout)
  end

  def self.config(**args)
    @config ||= Config.new(
      args[:months],
      Array.wrap(args[:list] || Rails.root.glob("**/data_taster_export_tables.yml")),
      args[:source_client] || raise(ArgumentError, "DataTaster.config missing source_client"),
      args[:working_client] || raise(ArgumentError, "DataTaster.config missing working_client"),
      args[:include_insert] || false
    )
  end

  def self.confection
    @confection ||= DataTaster::Confection.new.assemble
  end

  def self.sample!
    DataTaster
      .config
      .source_client
      .query("SHOW tables").collect { |t| t[t.keys.first] }
      .each do |table_name|
        DataTaster::Sample.new(table_name).serve!
      end
  end

  def self.safe_execute(sql, client = DataTaster.config.working_client)
    foreign_key_check = client.query("SELECT @@FOREIGN_KEY_CHECKS").first["@@FOREIGN_KEY_CHECKS"]

    begin
      client.query("SET FOREIGN_KEY_CHECKS=0")
      client.query(sql)
    ensure
      client.query("SET FOREIGN_KEY_CHECKS=#{foreign_key_check};")
    end
  end

  Config = Struct.new(:months, :list, :source_client, :working_client, :include_insert)
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
data_taster-0.4.0 lib/data_taster.rb
data_taster-0.3.0 lib/data_taster.rb
data_taster-0.2.2 lib/data_taster.rb