Class: StreamsOut

Inherits:
Object show all
Defined in:
lib/streams_out.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStreamsOut

Returns a new instance of StreamsOut.



9
10
11
# File 'lib/streams_out.rb', line 9

def initialize
  @streams = []
end

Instance Attribute Details

#streamsObject

Returns the value of attribute streams.



7
8
9
# File 'lib/streams_out.rb', line 7

def streams
  @streams
end

Instance Method Details

#append_stream_line(stream, line) ⇒ Object



13
14
15
# File 'lib/streams_out.rb', line 13

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

#stream_lines(stream) ⇒ Object



17
18
19
20
21
# File 'lib/streams_out.rb', line 17

def stream_lines(stream)
  @streams.select do |v|
    v[:stream] == stream
  end.map(&:line)
end

#write_execution_output_to_file(filespec) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/streams_out.rb', line 23

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