Sha256: 2882a1aca3637bc048b46a2bba00b46e6ceba10516b902b60689c12ed4527cfc

Contents?: true

Size: 836 Bytes

Versions: 2

Compression:

Stored size: 836 Bytes

Contents

module DataForge
  module Transformation
    class RubyTransformationContext

      def initialize(writers)
        @_writer_names = writers.map { |writer| writer.name }
        @_writers_hash = Hash[@_writer_names.zip writers]
        @_default_writer = writers.first
      end



      def output(record, options = {})
        if options.has_key? :to
          Array(options[:to]).each do |target_writer_name|
            raise "Unknown target file '#{target_writer_name}' for `output` command" unless @_writer_names.include? target_writer_name
            @_writers_hash[target_writer_name].write record
          end
        else
          raise "Missing :to directive for `output` command in multiple file transformation" if @_writers_hash.count > 1
          @_default_writer.write record
        end
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
data_forge-0.1.1 lib/data_forge/transformation/ruby_transformation_context.rb
data_forge-0.1 lib/data_forge/transformation/ruby_transformation_context.rb