Class: DataForge::Transformation::RubyTransformationContext
- Inherits:
-
Object
- Object
- DataForge::Transformation::RubyTransformationContext
- Defined in:
- lib/data_forge/transformation/ruby_transformation_context.rb
Instance Method Summary collapse
-
#initialize(writers) ⇒ RubyTransformationContext
constructor
A new instance of RubyTransformationContext.
- #output(record, options = {}) ⇒ Object
Constructor Details
#initialize(writers) ⇒ RubyTransformationContext
Returns a new instance of RubyTransformationContext.
5 6 7 8 9 |
# File 'lib/data_forge/transformation/ruby_transformation_context.rb', line 5 def initialize(writers) @_writer_names = writers.map { |writer| writer.name } @_writers_hash = Hash[@_writer_names.zip writers] @_default_writer = writers.first end |
Instance Method Details
#output(record, options = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/data_forge/transformation/ruby_transformation_context.rb', line 13 def output(record, = {}) if .has_key? :to Array([: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 |