Class: Berkshelf::Packager
- Inherits:
-
Object
- Object
- Berkshelf::Packager
- Defined in:
- lib/berkshelf/packager.rb
Overview
A class for archiving and compressing directory containing one or more cookbooks.
Example:
Archiving a path containing the cookbooks:
* "/path/to/cookbooks/my_face"
* "/path/to/cookbooks/nginx"
irb> source = "/path/to/cookbooks"
irb> packager = Berkshelf::Packager.new("some/path/cookbooks.tar.gz")
irb> packager.run(source) #=> "some/path/cookbooks.tar.gz"
Defined Under Namespace
Classes: RelativeTarWriter
Instance Attribute Summary collapse
- #out_file ⇒ String readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(out_file) ⇒ Packager
constructor
A new instance of Packager.
-
#run(source) ⇒ String
Archive the contents of given path.
-
#validate! ⇒ nil
Validate that running the packager would be successful.
Constructor Details
#initialize(out_file) ⇒ Packager
Returns a new instance of Packager.
28 29 30 31 |
# File 'lib/berkshelf/packager.rb', line 28 def initialize(out_file) @out_file = out_file.to_s @out_dir, @filename = File.split(@out_file) end |
Instance Attribute Details
#out_file ⇒ String (readonly)
24 25 26 |
# File 'lib/berkshelf/packager.rb', line 24 def out_file @out_file end |
Class Method Details
.validate_destination(path) ⇒ Object
18 19 20 |
# File 'lib/berkshelf/packager.rb', line 18 def validate_destination(path) path.to_s end |
Instance Method Details
#run(source) ⇒ String
Archive the contents of given path
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/berkshelf/packager.rb', line 43 def run(source) begin dest = Zlib::GzipWriter.open(out_file) tar = RelativeTarWriter.new(dest, source) Find.find(source) do |entry| next if source == entry Minitar.pack_file(entry, tar) end ensure tar.close dest.close end out_file rescue SystemCallError => ex raise PackageError, ex end |
#validate! ⇒ nil
Validate that running the packager would be successful. Returns nil if would be successful and raises an error if would not.
69 70 71 72 |
# File 'lib/berkshelf/packager.rb', line 69 def validate! raise PackageError, "Path is not a directory: #{out_dir}" unless File.directory?(out_dir) raise PackageError, "Directory is not writable: #{out_dir}" unless File.writable?(out_dir) end |