module ETL #:nodoc: module Control #:nodoc: class Destination attr_reader :control, :configuration, :mapping attr_accessor :buffer_size, :current_row class << self def class_for_name(name) ETL::Control.const_get("#{name.to_s.classify}Destination") end end def initialize(control, configuration, mapping) @control = control @configuration = configuration @mapping = mapping @buffer_size = configuration[:buffer_size] ||= 1000 end def current_row @current_row ||= 1 end # Abstract method def write(row) buffer << row flush if buffer.length >= buffer_size end # Abstract method def flush raise NotImplementedError, "flush method must be implemented by subclasses" end # Abstract method def close raise NotImplementedError, "close method must be implemented by subclasses" end protected def buffer @buffer ||= [] end def generators @generators ||= {} end # Get the order of elements from the source order def order_from_source order = [] control.sources.first.definition.each do |item| case item when Hash order << item[:name] else order << item end end order end end end end Dir[File.dirname(__FILE__) + "/destination/*.rb"].each { |file| require(file) }