Class: DataTaster::Sample

Inherits:
Object
  • Object
show all
Defined in:
lib/data_taster/sample.rb

Overview

Selects and processes tables from the source_db to insert (or query) into the working_db

Instance Method Summary collapse

Constructor Details

#initialize(table_name) ⇒ Sample

Returns a new instance of Sample.



7
8
9
10
11
12
13
# File 'lib/data_taster/sample.rb', line 7

def initialize(table_name)
  @table_name = table_name
  @include_insert = DataTaster.config.include_insert
  @collection = DataTaster::Collection.new(
    table_name
  ).assemble
end

Instance Method Details

#serve!Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/data_taster/sample.rb', line 15

def serve!
  # Any table that does not return SQL is considered deprecated and we should fully skip it
  if collection.empty? && include_insert
    DataTaster.safe_execute("DROP TABLE IF EXISTS #{table_name}")
  else
    ensure_empty_table
    process_select(collection[:select])
    DataTaster::Sanitizer.new(table_name, collection[:sanitize]).clean!
  end
end