class ForemanInventoryUpload::Async::ProgressOutput

Public Class Methods

get(label) click to toggle source
# File lib/foreman_inventory_upload/async/progress_output.rb, line 4
def self.get(label)
  ProgressOutput.new(label, :reader)
end
new(label, mode) click to toggle source
# File lib/foreman_inventory_upload/async/progress_output.rb, line 12
def initialize(label, mode)
  @label = label
  @mode = mode
end
register(label) click to toggle source
# File lib/foreman_inventory_upload/async/progress_output.rb, line 8
def self.register(label)
  ProgressOutput.new(label, :writer)
end

Public Instance Methods

buffer() click to toggle source
# File lib/foreman_inventory_upload/async/progress_output.rb, line 17
def buffer
  @buffer ||= begin
                File.open(file_name, file_mode)
              rescue Errno::ENOENT
                StringIO.new
              end
end
close() click to toggle source
# File lib/foreman_inventory_upload/async/progress_output.rb, line 34
def close
  @buffer&.close
end
full_output() click to toggle source
# File lib/foreman_inventory_upload/async/progress_output.rb, line 25
def full_output
  buffer.read
end
status() click to toggle source
# File lib/foreman_inventory_upload/async/progress_output.rb, line 38
def status
  File.read(file_name(:status))
rescue Errno::ENOENT
  ''
end
status=(status) click to toggle source
# File lib/foreman_inventory_upload/async/progress_output.rb, line 44
def status=(status)
  File.atomic_write(file_name(:status)) do |status_file|
    status_file.write(status)
  end
end
write_line(line) click to toggle source
# File lib/foreman_inventory_upload/async/progress_output.rb, line 29
def write_line(line)
  buffer << line
  buffer.fsync
end

Private Instance Methods

file_mode() click to toggle source
# File lib/foreman_inventory_upload/async/progress_output.rb, line 52
def file_mode
  (@mode == :reader) ? 'r' : 'w'
end
file_name(type = 'out') click to toggle source
# File lib/foreman_inventory_upload/async/progress_output.rb, line 56
def file_name(type = 'out')
  File.join(ForemanInventoryUpload.outputs_folder, "#{@label}.#{type}")
end