Add support for tarballing up directories to send along to the hosts
This commit is contained in:
parent
06d2fc1e64
commit
4e0d26fb43
|
@ -17,4 +17,5 @@ Gem::Specification.new do |gem|
|
|||
|
||||
gem.add_dependency 'fog'
|
||||
gem.add_dependency 'thor'
|
||||
gem.add_dependency 'minitar'
|
||||
end
|
||||
|
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue