Class: ETL::Processor::TruncateProcessor

Inherits:
Processor show all
Defined in:
lib/etl/processor/truncate_processor.rb

Overview

A processor which will truncate a table. Use as a pre-processor for cleaning out a table prior to loading

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (TruncateProcessor) initialize(control, configuration)

Initialize the processor

Options:

  • :target: The target connection

  • :table: The table name

  • :options: Optional truncate options



18
19
20
21
22
23
24
# File 'lib/etl/processor/truncate_processor.rb', line 18

def initialize(control, configuration)
  super
  #@file = File.join(File.dirname(control.file), configuration[:file])
  @target = configuration[:target] || {}
  @table = configuration[:table]
  @options = configuration[:options] 
end

Instance Attribute Details

- (Object) table (readonly)

Defines the table to truncate



7
8
9
# File 'lib/etl/processor/truncate_processor.rb', line 7

def table
  @table
end

- (Object) target (readonly)

Defines the database connection to use



10
11
12
# File 'lib/etl/processor/truncate_processor.rb', line 10

def target
  @target
end

Instance Method Details

- (Object) process



26
27
28
29
30
# File 'lib/etl/processor/truncate_processor.rb', line 26

def process
  conn = ETL::Engine.connection(target)
  @options ||= 'RESTART IDENTITY' if conn.class.name =~ /postgres/i
  conn.truncate(table_name, @options)
end