Class: MxxRu::Generators::Impl::StdReceiver

Inherits:
Object
  • Object
show all
Defined in:
lib/mxx_ru/generators/impl/std_receiver.rb

Overview

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' )

Instance Method Summary collapse

Instance Method Details

#receive(result, output_file_name) ⇒ Object

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.



63
64
65
66
67
68
69
70
71
# 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