Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support for tarballing up directories to send along to the hosts

  • Loading branch information...
commit 4e0d26fb434019479c6f22901eff001d79a3e3d3 1 parent 06d2fc1
@rtyler authored
View
1  blimpy.gemspec
@@ -17,4 +17,5 @@ Gem::Specification.new do |gem|
gem.add_dependency 'fog'
gem.add_dependency 'thor'
+ gem.add_dependency 'minitar'
end
View
31 lib/blimpy/livery.rb
@@ -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
View
19 spec/blimpy/livery_spec.rb
@@ -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

0 comments on commit 4e0d26f

Please sign in to comment.
Something went wrong with that request. Please try again.