Sha256: 5be7e8528dc90b19b61fa1c02ee75578e08e4cdcfbf9ac002d65b7bfae43f005

Contents?: true

Size: 798 Bytes

Versions: 43

Compression:

Stored size: 798 Bytes

Contents

# frozen_string_literal: true

module RBS
  module Collection
    class Cleaner
      attr_reader :lock

      def initialize(lockfile_path:)
        @lock = Config.from_path(lockfile_path)
      end

      def clean
        lock.repo_path.glob('*/*') do |dir|
          *_, gem_name, version = dir.to_s.split('/')
          gem_name or raise
          version or raise
          next if needed? gem_name, version

          case
          when dir.symlink?
            dir.unlink
          when dir.directory?
            FileUtils.remove_entry_secure(dir.to_s)
          else
            raise
          end
        end
      end

      def needed?(gem_name, version)
        gem = lock.gem(gem_name)
        return false unless gem

        gem['version'] == version
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
rbs-3.8.1 lib/rbs/collection/cleaner.rb
rbs-3.8.0 lib/rbs/collection/cleaner.rb
rbs-3.8.0.pre.1 lib/rbs/collection/cleaner.rb
rbs-3.7.0.pre.1 lib/rbs/collection/cleaner.rb
rbs-3.7.0.dev.1 lib/rbs/collection/cleaner.rb
rbs-3.6.1 lib/rbs/collection/cleaner.rb
rbs-3.6.0 lib/rbs/collection/cleaner.rb
rbs-3.6.0.pre.3 lib/rbs/collection/cleaner.rb
rbs-3.6.0.pre.2 lib/rbs/collection/cleaner.rb
rbs-3.6.0.pre.1 lib/rbs/collection/cleaner.rb
rbs-3.6.0.dev.1 lib/rbs/collection/cleaner.rb
rbs-3.5.3 lib/rbs/collection/cleaner.rb
rbs-3.5.2 lib/rbs/collection/cleaner.rb
rbs-3.5.1 lib/rbs/collection/cleaner.rb
rbs-3.5.1.pre.1 lib/rbs/collection/cleaner.rb
rbs-3.5.0 lib/rbs/collection/cleaner.rb
rbs-3.5.0.pre.2 lib/rbs/collection/cleaner.rb
rbs-3.5.0.pre.1 lib/rbs/collection/cleaner.rb
rbs-3.4.4 lib/rbs/collection/cleaner.rb
rbs-3.4.3 lib/rbs/collection/cleaner.rb