Sha256: a190b277750c21b62844ca95d4af0e2a9cf24f555ff22b582f6389043eb368c3

Contents?: true

Size: 577 Bytes

Versions: 20

Compression:

Stored size: 577 Bytes

Contents

class KuberKit::Tools::BuildDirCleaner
  include KuberKit::Import[
    "shell.bash_commands",
    "shell.local_shell",
  ]

  KEEP_DIRS_COUNT = 10

  def call(parent_dir:)
    dirs_to_delete = get_ancient_builds_dirs(parent_dir: parent_dir)

    dirs_to_delete.each do |dir|
      bash_commands.rm_rf(local_shell, dir)
    end
  end

  private
    def get_ancient_builds_dirs(parent_dir:)
      all_dirs  = Dir.glob("#{parent_dir}/*")
      skip_dirs = all_dirs
        .sort_by{ |f| File.ctime(f) }
        .reverse[0...KEEP_DIRS_COUNT]

      all_dirs - skip_dirs
    end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
kuber_kit-0.9.3 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-0.9.2 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-0.9.1 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-0.9.0 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-0.8.8 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-0.8.7 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-0.8.6 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-0.8.5 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-0.8.4 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-0.8.3 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-0.8.2 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-0.8.1 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-0.8.0 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-0.7.1 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-0.7.0 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-0.6.4 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-0.6.3 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-0.6.2 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-0.6.1 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-0.6.0 lib/kuber_kit/tools/build_dir_cleaner.rb