lib/etl/control/destination.rb in activewarehouse-etl-0.5.2 vs lib/etl/control/destination.rb in activewarehouse-etl-0.6.0
- old
+ new
@@ -15,10 +15,16 @@
attr_accessor :buffer_size
# Unique flag.
attr_accessor :unique
+ # A condition for writing
+ attr_accessor :condition
+
+ # An array of rows to append to the destination
+ attr_accessor :append_rows
+
class << self
# Get the destination class for the specified name.
#
# For example if name is :database or 'database' then the DatabaseDestination class
# is returned
@@ -34,24 +40,30 @@
# * <tt>configuration</tt>: The configuration Hash
# * <tt>mapping</tt>: The mapping Hash
#
# Options:
# * <tt>:buffer_size</tt>: The output buffer size (default 1000 records)
+ # * <tt>:condition</tt>: A conditional proc that must return true for the row to be written
+ # * <tt>:append_rows</tt>: An array of rows to append
def initialize(control, configuration, mapping)
@control = control
@configuration = configuration
@mapping = mapping
@buffer_size = configuration[:buffer_size] ||= 1000
+ @condition = configuration[:condition]
+ @append_rows = configuration[:append_rows]
end
# Get the current row number
def current_row
@current_row ||= 1
end
# Write the given row
def write(row)
- buffer << row
+ if @condition.nil? || @condition.call(row)
+ buffer << row
+ end
flush if buffer.length >= buffer_size
end
# Abstract method
def flush
\ No newline at end of file