Class: ETL::Processor::TruncateProcessor

Inherits:
Processor
  • Object
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

#initialize(control, configuration) ⇒ TruncateProcessor

Returns a new instance of TruncateProcessor.



11
12
13
14
15
16
17
# File 'lib/etl/processor/truncate_processor.rb', line 11

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

Instance Attribute Details

#tableObject (readonly)

Defines the table to truncate



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

def table
  @table
end

#targetObject (readonly)

Defines the database connection information



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

def target
  @target
end

Instance Method Details

#connectObject

Connect to the database



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

def connect
  ETL::ActiveRecord::Base.establish_connection(
      :adapter  => (target[:adapter] || :mysql),
      :username => (target[:username] || 'root'),
      :host     => (target[:host] || 'localhost'),
      :password => target[:password],
      :database => target[:database] 
  )
end

#processObject



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

def process
  conn = ETL::ActiveRecord::Base.connection
  conn.truncate(table)
end