Sha256: 2597811cc60e9d28d733315c60a2583c18c1f9f1dd65c2da4a498737bdabed1e

Contents?: true

Size: 1.31 KB

Versions: 139

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'
require 'eac_ruby_utils/fs/temp'
require 'filesize'

module EacFs
  class Logs
    require_sub __FILE__

    # @param label [Symbol]
    # @return [EacRubyUtils::Fs::Temp::File]
    def [](label)
      log_set.fetch(sanitize_label(label)).file
    end

    # @param label [Symbol]
    # @return [EacFs::Logs]
    def add(label)
      file = ::EacFs::Logs::File.new(sanitize_label(label))
      log_set[file.label] = file

      self
    end

    # @return [EacFs::Logs]
    def clean_all
      log_set.values.each(&:clean)
    end

    # @return [EacFs::Logs]
    def remove_all
      log_set.each_key { |label| remove(label) }

      self
    end

    # @param label [Symbol]
    def remove(label)
      log_set.fetch(sanitize_label(label)).remove
      log_set.delete(sanitize_label(label))
    end

    # @param length [Integer]
    # @return [String]
    def truncate_all(length = ::EacFs::Logs::File::TRUNCATE_DEFAULT_LENGTH)
      "Files: #{log_set.length}\n" +
        log_set.values.map { |file| file.truncate_with_label(length) }.join
    end

    private

    # @param label [Object]
    # @return [Symbol]
    def sanitize_label(label)
      label.to_sym
    end

    # @return [Hash<Symbol, EacFs::Logs::File>]
    def log_set
      @log_set ||= {}
    end
  end
end

Version data entries

139 entries across 139 versions & 3 rubygems

Version Path
eac_tools-0.76.0 sub/eac_fs/lib/eac_fs/logs.rb
eac_tools-0.75.2 sub/eac_fs/lib/eac_fs/logs.rb
eac_tools-0.75.1 sub/eac_fs/lib/eac_fs/logs.rb
eac_tools-0.75.0 sub/eac_fs/lib/eac_fs/logs.rb
eac_tools-0.74.1 sub/eac_fs/lib/eac_fs/logs.rb
eac_tools-0.74.0 sub/eac_fs/lib/eac_fs/logs.rb
eac_tools-0.73.0 sub/eac_fs/lib/eac_fs/logs.rb
eac_tools-0.72.0 sub/eac_fs/lib/eac_fs/logs.rb
eac_tools-0.70.1 sub/eac_fs/lib/eac_fs/logs.rb
eac_tools-0.70.0 sub/eac_fs/lib/eac_fs/logs.rb
eac_tools-0.69.1 sub/eac_fs/lib/eac_fs/logs.rb
eac_tools-0.69.0 sub/eac_fs/lib/eac_fs/logs.rb
eac_tools-0.68.0 sub/eac_fs/lib/eac_fs/logs.rb
eac_tools-0.67.1 sub/eac_fs/lib/eac_fs/logs.rb
eac_tools-0.67.0 sub/eac_fs/lib/eac_fs/logs.rb
eac_tools-0.66.0 sub/eac_fs/lib/eac_fs/logs.rb
eac_tools-0.65.1 sub/eac_fs/lib/eac_fs/logs.rb
eac_tools-0.65.0 sub/eac_fs/lib/eac_fs/logs.rb
eac_tools-0.64.0 sub/eac_fs/lib/eac_fs/logs.rb
eac_tools-0.63.0 sub/eac_fs/lib/eac_fs/logs.rb