class MxxRu::Generators::Impl::StdReceiver

Objects of this class will send result of code generation to standard output stream or into specified output file.

Usage:

receiver = StdReceiver.new
# Send result to $stdout.
receiver.receive( result, nil )
# Send result to file.
receiver.receive( result, 'some_file' )

Public Instance Methods

receive( result, output_file_name ) click to toggle source

Sends result to output file if output_file_name isn't nil.

If result is going to output file then:

  1. Temporary file will be created.

  2. Result will be written to temporary file.

  3. Output file will be deleted if exists.

  4. Temporary file will be moved to output file.

# File lib/mxx_ru/generators/impl/std_receiver.rb, line 63
def receive( result, output_file_name )
  if output_file_name
    tmp_file_name = MxxRu::Util::TmpFiles.instance.create( result )
    FileUtils.rm( output_file_name, :force => true )
    FileUtils.cp( tmp_file_name, output_file_name )
  else
    $stdout.write( result )
  end
end