Class: RepoFixture::ZipStrategy
- Inherits:
-
Object
- Object
- RepoFixture::ZipStrategy
- Defined in:
- lib/repo-fixture/zip_strategy.rb
Class Method Summary collapse
Class Method Details
.export(output_file, fixture) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/repo-fixture/zip_strategy.rb', line 10 def export(output_file, fixture) repo = fixture.repo working_dir_path_length = repo.working_dir.to_s.length Zip::File.open(output_file, Zip::File::CREATE) do |zipfile| Dir.glob("#{repo.working_dir}/**/**", File::FNM_DOTMATCH).each do |file| if File.file?(file) # plus 1 to remove the leading slash relative_file = file[(working_dir_path_length + 1)..-1] zipfile.add(relative_file, file) end end end end |
.load(file) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/repo-fixture/zip_strategy.rb', line 24 def load(file) output_dir = TmpRepo.random_dir Zip::File.open(file) do |zipfile| zipfile.each do |entry| output_file = File.join(output_dir, entry.name) FileUtils.mkdir_p(File.dirname(output_file)) entry.extract(output_file) end end Fixture.new( TmpRepo.new(output_dir) ) end |