Module: Kernel
- Defined in:
- lib/jets/core_ext/kernel.rb
Overview
Works with jets/io.rb
Constant Summary collapse
- @@io_buffer =
[]
Instance Method Summary collapse
-
#io_buffer ⇒ Object
TODO: implement other methods that write output: p, print, printf, putc, puts, sprintf? Also, would be nice to figure out pp method also.
-
#io_flush ⇒ Object
Note: Writing binary data to the log will crash the process with an error like this: jets/lib/jets/core_ext/kernel.rb:20:in ‘write’: “x89” from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError) Rescue and discard it to keep the process alive.
- #original_puts ⇒ Object
- #puts(message) ⇒ Object
Instance Method Details
#io_buffer ⇒ Object
TODO: implement other methods that write output: p, print, printf, putc, puts, sprintf? Also, would be nice to figure out pp method also.
15 16 17 |
# File 'lib/jets/core_ext/kernel.rb', line 15 def io_buffer @@io_buffer end |
#io_flush ⇒ Object
Note: Writing binary data to the log will crash the process with an error like this:
jets/lib/jets/core_ext/kernel.rb:20:in `write': "\x89" from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError)
Rescue and discard it to keep the process alive.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/jets/core_ext/kernel.rb', line 22 def io_flush chunk = @@io_buffer.join("\n") begin IO.write("/tmp/jets-output.log", chunk) # Writing to log with binary content will crash the process so rescuing it and writing an info message. rescue Encoding::UndefinedConversionError => e = "Encoding::UndefinedConversionError: Binary data was written to Jets::IO buffer. Writing binary data to the log will crash the process, so discarding it. This is an info message only. If you want to return binary data please base64 encode the data." IO.write("/tmp/jets-output.log", ) end @@io_buffer = [] end |
#original_puts ⇒ Object
5 |
# File 'lib/jets/core_ext/kernel.rb', line 5 alias_method :original_puts, :puts |
#puts(message) ⇒ Object
6 7 8 9 |
# File 'lib/jets/core_ext/kernel.rb', line 6 def puts() @@io_buffer << original_puts() end |