Class: MxxRu::Generators::Impl::StdReceiver
- Inherits:
-
Object
- Object
- MxxRu::Generators::Impl::StdReceiver
- 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
-
#receive(result, output_file_name) ⇒ Object
Sends result to output file if output_file_name isn’t nil.
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:
-
Temporary file will be created.
-
Result will be written to temporary file.
-
Output file will be deleted if exists.
-
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 |