Sha256: c116ac4afbd8bfa09cadcb405f250947665359b2ed992fc481238def7ac1a897

Contents?: true

Size: 930 Bytes

Versions: 1

Compression:

Stored size: 930 Bytes

Contents

module ETL
  module Processor
    # A processor which will truncate a table. Use as a pre-processor for cleaning out a table
    # prior to loading
    class TruncateProcessor < ETL::Processor::Processor
      attr_reader :file, :table
      def initialize(control, configuration)
        super
        @file = File.join(File.dirname(control.file), configuration[:file])
        @table = configuration[:table]
        connect
      end
      def process
        conn = ActiveRecord::Base.connection
        conn.truncate
      end
      
      # Connect to the database
      def connect
        ActiveRecord::Base.establish_connection(
            :adapter  => (target[:adapter] || :mysql),
            :username => (target[:username] || 'root'),
            :host     => (target[:host] || 'localhost'),
            :password => target[:password],
            :database => target[:database] 
        )
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activewarehouse-etl-0.4.0 lib/etl/processor/truncate_processor.rb