Class: Gitballs::Registry
- Inherits:
-
Object
- Object
- Gitballs::Registry
- Defined in:
- lib/gitballs/registry.rb
Constant Summary collapse
- EXTRACTORS =
{ "gem" => :extract_gem, "npm" => :extract_tgz, "pypi" => :extract_tgz, "cargo" => :extract_tgz, "nuget" => :extract_nupkg, "go" => :extract_zip, "hex" => :extract_tgz, "packagist" => :extract_zip }.freeze
Instance Method Summary collapse
- #cleanup_nupkg_metadata(destination) ⇒ Object
- #extract(tarball_path, destination) ⇒ Object
- #extract_gem(tarball_path, destination) ⇒ Object
- #extract_nupkg(tarball_path, destination) ⇒ Object
- #extract_tgz(tarball_path, destination) ⇒ Object
- #extract_zip(tarball_path, destination) ⇒ Object
-
#initialize(purl_type) ⇒ Registry
constructor
A new instance of Registry.
- #move_nested_package_dir(destination) ⇒ Object
Constructor Details
#initialize(purl_type) ⇒ Registry
Returns a new instance of Registry.
16 17 18 19 |
# File 'lib/gitballs/registry.rb', line 16 def initialize(purl_type) @purl_type = purl_type @extractor = EXTRACTORS[purl_type] || raise(Error, "Unsupported type: #{purl_type}") end |
Instance Method Details
#cleanup_nupkg_metadata(destination) ⇒ Object
62 63 64 65 66 |
# File 'lib/gitballs/registry.rb', line 62 def (destination) FileUtils.rm_rf(Dir.glob(File.join(destination, "_rels"))) FileUtils.rm_rf(Dir.glob(File.join(destination, "[Content_Types].xml"))) FileUtils.rm_rf(Dir.glob(File.join(destination, "*.nuspec"))) end |
#extract(tarball_path, destination) ⇒ Object
21 22 23 |
# File 'lib/gitballs/registry.rb', line 21 def extract(tarball_path, destination) send(@extractor, tarball_path, destination) end |
#extract_gem(tarball_path, destination) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/gitballs/registry.rb', line 25 def extract_gem(tarball_path, destination) system("tar", "-C", destination, "-xf", tarball_path, exception: true) data_tar = File.join(destination, "data.tar.gz") if File.exist?(data_tar) system("tar", "-C", destination, "-xzf", data_tar, exception: true) FileUtils.rm_f([data_tar, File.join(destination, "metadata.gz"), File.join(destination, "checksums.yaml.gz")]) end end |
#extract_nupkg(tarball_path, destination) ⇒ Object
44 45 46 47 |
# File 'lib/gitballs/registry.rb', line 44 def extract_nupkg(tarball_path, destination) system("unzip", "-q", "-o", tarball_path, "-d", destination, exception: true) (destination) end |
#extract_tgz(tarball_path, destination) ⇒ Object
34 35 36 37 |
# File 'lib/gitballs/registry.rb', line 34 def extract_tgz(tarball_path, destination) system("tar", "-C", destination, "-xzf", tarball_path, exception: true) move_nested_package_dir(destination) end |
#extract_zip(tarball_path, destination) ⇒ Object
39 40 41 42 |
# File 'lib/gitballs/registry.rb', line 39 def extract_zip(tarball_path, destination) system("unzip", "-q", "-o", tarball_path, "-d", destination, exception: true) move_nested_package_dir(destination) end |
#move_nested_package_dir(destination) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/gitballs/registry.rb', line 49 def move_nested_package_dir(destination) entries = Dir.children(destination).reject { |f| f.start_with?(".") } return unless entries.size == 1 nested = File.join(destination, entries.first) return unless File.directory?(nested) Dir.children(nested).each do |child| FileUtils.mv(File.join(nested, child), destination) end FileUtils.rmdir(nested) end |