Skip to content
This repository has been archived by the owner on Mar 8, 2018. It is now read-only.

Commit

Permalink
Add support for tarballing up directories to send along to the hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
R. Tyler Croy committed Apr 29, 2012
1 parent 06d2fc1 commit 4e0d26f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions blimpy.gemspec
Expand Up @@ -17,4 +17,5 @@ Gem::Specification.new do |gem|

gem.add_dependency 'fog'
gem.add_dependency 'thor'
gem.add_dependency 'minitar'
end
31 changes: 31 additions & 0 deletions 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
19 changes: 19 additions & 0 deletions 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.