Sha256: 2c6f21f1a4afb6f737f62d45eb44d473fea0fdd265834acfba1ecb65c7e41505

Contents?: true

Size: 769 Bytes

Versions: 3

Compression:

Stored size: 769 Bytes

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

# encoding=utf-8

class StreamsOut
  attr_accessor :streams

  def initialize
    @streams = []
  end

  def append_stream_line(stream, line)
    @streams << { stream: stream, line: line, timestamp: Time.now }
  end

  def write_execution_output_to_file(filespec)
    FileUtils.mkdir_p File.dirname(filespec)

    output = @streams.map do |entry|
      case entry[:stream]
      when ExecutionStreams::STD_OUT
        entry[:line]
        # "OUT: #{entry[:line]}"
      when ExecutionStreams::STD_ERR
        entry[:line]
        # "ERR: #{entry[:line]}"
      when ExecutionStreams::STD_IN
        entry[:line]
        # " IN: #{entry[:line]}"
      end
    end.join("\n")

    File.write(filespec, output)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
markdown_exec-2.3.0 lib/streams_out.rb
markdown_exec-2.2.0 lib/streams_out.rb
markdown_exec-2.1.0 lib/streams_out.rb