Module: Blockbuster::Extractor

Included in:
Delta, Master
Defined in:
lib/blockbuster/concerns/extractor.rb

Overview

extracts files from gzipped tarballs

Instance Method Summary collapse

Instance Method Details

#extract_cassettesObject



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/blockbuster/concerns/extractor.rb', line 4

def extract_cassettes
  return unless File.exist?(file_path)

  File.open(file_path, 'rb') do |file|
    Zlib::GzipReader.wrap(file) do |gz|
      Gem::Package::TarReader.new(gz) do |tar|
        tar.each do |entry|
          untar_file(entry) if entry.file?
        end
      end
    end
  end
end

#save_to_disk(entry, contents) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/blockbuster/concerns/extractor.rb', line 25

def save_to_disk(entry, contents)
  destination = File.join configuration.test_directory, entry.full_name

  FileUtils.mkdir_p(File.dirname(destination))
  File.open(destination, 'wb') do |cass|
    cass.write(contents)
  end
  File.chmod(entry.header.mode, destination)
end

#untar_file(entry) ⇒ Object



18
19
20
21
22
23
# File 'lib/blockbuster/concerns/extractor.rb', line 18

def untar_file(entry)
  contents = entry.read
  @comparator.add(entry.full_name, Digest::MD5.hexdigest(contents), file_name)

  save_to_disk(entry, contents) unless configuration.local_mode
end