Class: Scripted::Output::CommandLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/scripted/output/command_logger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger, command) ⇒ CommandLogger

Returns a new instance of CommandLogger.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/scripted/output/command_logger.rb', line 9

def initialize(logger, command)

  @logger, @command = logger, command

  @read, @write = IO.pipe

  @reader = Thread.new do
    read.each_char do |char|
      logger.send_to_formatters :each_char, char, command
    end
  end

end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



5
6
7
# File 'lib/scripted/output/command_logger.rb', line 5

def command
  @command
end

#loggerObject (readonly)

Returns the value of attribute logger.



5
6
7
# File 'lib/scripted/output/command_logger.rb', line 5

def logger
  @logger
end

#readObject (readonly)

Returns the value of attribute read.



7
8
9
# File 'lib/scripted/output/command_logger.rb', line 7

def read
  @read
end

#readerObject (readonly)

Returns the value of attribute reader.



7
8
9
# File 'lib/scripted/output/command_logger.rb', line 7

def reader
  @reader
end

#writeObject (readonly)

Returns the value of attribute write.



7
8
9
# File 'lib/scripted/output/command_logger.rb', line 7

def write
  @write
end

Instance Method Details

#closeObject



33
34
35
36
37
38
# File 'lib/scripted/output/command_logger.rb', line 33

def close
  sync
  reader.exit
  write.close
  read.close
end

#syncObject



27
28
29
30
31
# File 'lib/scripted/output/command_logger.rb', line 27

def sync
  read.sync
  write.sync
  sleep 0.01
end

#to_ioObject



23
24
25
# File 'lib/scripted/output/command_logger.rb', line 23

def to_io
  write
end