Sha256: 5ec7eeccbf40dd62135157f640fec2bd0eb5158f27f50a73c98bfa73e13f4507

Contents?: true

Size: 1.13 KB

Versions: 4

Compression:

Stored size: 1.13 KB

Contents

module ETL #:nodoc:
  module Processor #:nodoc:
    # 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
      
      # Defines the table to truncate
      attr_reader :table
      
      # Defines the database connection information
      attr_reader :target
      def initialize(control, configuration)
        super
        #@file = File.join(File.dirname(control.file), configuration[:file])
        @target = configuration[:target] || {}
        @table = configuration[:table]
        connect
      end
      def process
        conn = ETL::ActiveRecord::Base.connection
        conn.truncate(table)
      end
      
      # Connect to the database
      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
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
activewarehouse-etl-0.5.1 lib/etl/processor/truncate_processor.rb
activewarehouse-etl-0.6.0 lib/etl/processor/truncate_processor.rb
activewarehouse-etl-0.6.1 lib/etl/processor/truncate_processor.rb
activewarehouse-etl-0.5.2 lib/etl/processor/truncate_processor.rb