This repository has been archived by the owner on Mar 8, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for tarballing up directories to send along to the hosts
- Loading branch information
R. Tyler Croy
committed
Apr 29, 2012
1 parent
06d2fc1
commit 4e0d26f
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'rubygems' | ||
require 'zlib' | ||
require 'archive/tar/minitar' | ||
|
||
module Blimpy | ||
class Livery | ||
def self.tarball_directory(directory) | ||
if directory.nil? || !(File.directory? directory) | ||
raise ArgumentError, "The argument '#{directory}' doesn't appear to be a directory" | ||
end | ||
|
||
directory = File.expand_path(directory) | ||
short_name = File.basename(directory) | ||
|
||
Dir.chdir(File.expand_path(directory + '/../')) do | ||
self.gzip_for_directory(short_name, '/tmp') do |tgz| | ||
Archive::Tar::Minitar.pack(short_name, tgz) | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def self.gzip_for_directory(directory, root) | ||
filename = File.join(root, "#{directory}.tar.gz") | ||
yield Zlib::GzipWriter.new(File.open(filename, 'wb')) | ||
filename | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'spec_helper' | ||
require 'blimpy/livery' | ||
|
||
describe Blimpy::Livery do | ||
context 'class methods' do | ||
describe '#tarball_directory' do | ||
subject { Blimpy::Livery } # No instantiating! | ||
it 'should raise an exception if the directory doesn\'t exist' do | ||
expect { | ||
subject.tarball_directory(nil) | ||
}.to raise_error(ArgumentError) | ||
|
||
expect { | ||
subject.tarball_directory('/tmp/never-gonna-give-you-up.lolz') | ||
}.to raise_error(ArgumentError) | ||
end | ||
end | ||
end | ||
end |