class EacRubyUtils::Fs::Logs

Constants

TRUNCATE_APPEND_TEXT
TRUNCATE_DEFAULT_LENGTH

Public Instance Methods

[](label) click to toggle source
# File lib/eac_ruby_utils/fs/logs.rb, line 13
def [](label)
  log_set.fetch(sanitize_label(label))
end
add(label) click to toggle source
# File lib/eac_ruby_utils/fs/logs.rb, line 17
def add(label)
  log_set[sanitize_label(label)] = ::EacRubyUtils::Fs::Temp.file

  self
end
remove(label) click to toggle source
# File lib/eac_ruby_utils/fs/logs.rb, line 29
def remove(label)
  log_set.fetch(sanitize_label(label)).remove
  log_set.delete(sanitize_label(label))
end
remove_all() click to toggle source
# File lib/eac_ruby_utils/fs/logs.rb, line 23
def remove_all
  log_set.each_key { |label| remove(label) }

  self
end
truncate(label, length = TRUNCATE_DEFAULT_LENGTH) click to toggle source
# File lib/eac_ruby_utils/fs/logs.rb, line 34
def truncate(label, length = TRUNCATE_DEFAULT_LENGTH)
  content = self[label].read.strip
  return content if content.length <= TRUNCATE_DEFAULT_LENGTH

  TRUNCATE_APPEND_TEXT + content[content.length - length + TRUNCATE_APPEND_TEXT.length,
                                 length - TRUNCATE_APPEND_TEXT.length]
end
truncate_all(length = TRUNCATE_DEFAULT_LENGTH) click to toggle source
# File lib/eac_ruby_utils/fs/logs.rb, line 42
def truncate_all(length = TRUNCATE_DEFAULT_LENGTH)
  s = "Files: #{log_set.length}\n"
  log_set.each do |label, path|
    x = truncate(label, length)
    y = [label, path, ::Filesize.from("#{path.size} B").pretty].join(' / ')
    s += x.blank? ? ">>> #{y} (Blank) <<<" : ">>> #{y}\n#{x}\n<<< #{y}\n"
  end
  s
end

Private Instance Methods

log_set() click to toggle source
# File lib/eac_ruby_utils/fs/logs.rb, line 58
def log_set
  @log_set ||= {}
end
sanitize_label(label) click to toggle source
# File lib/eac_ruby_utils/fs/logs.rb, line 54
def sanitize_label(label)
  label.to_sym
end