123456789_123456789_123456789_123456789_123456789_

Class: RBS::Collection::Cleaner

Relationships & Source Files
Inherits: Object
Defined in: lib/rbs/collection/cleaner.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(lockfile_path:) ⇒ Cleaner

[ GitHub ]

  
# File 'lib/rbs/collection/cleaner.rb', line 8

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

Instance Attribute Details

#lock (readonly)

[ GitHub ]

  
# File 'lib/rbs/collection/cleaner.rb', line 6

attr_reader :lock

Instance Method Details

#clean

[ GitHub ]

  
# File 'lib/rbs/collection/cleaner.rb', line 12

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

    FileUtils.remove_entry_secure(dir.to_s)
  end
end

#needed?(gem_name, version) ⇒ Boolean

[ GitHub ]

  
# File 'lib/rbs/collection/cleaner.rb', line 23

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

  gem['version'] == version
end