Class: Mixlib::Archive
- Inherits:
-
Object
- Object
- Mixlib::Archive
- Defined in:
- lib/mixlib/archive.rb,
lib/mixlib/archive/tar.rb,
lib/mixlib/archive/version.rb,
lib/mixlib/archive/lib_archive.rb
Defined Under Namespace
Classes: LibArchive, Log, Tar, TarError
Constant Summary collapse
- VERSION =
"1.1.3".freeze
Instance Attribute Summary collapse
-
#archiver ⇒ Object
(also: #extractor)
readonly
Returns the value of attribute archiver.
Class Method Summary collapse
Instance Method Summary collapse
- #create(files = [], gzip: false) ⇒ Object
- #extract(destination, perms: true, ignore: []) ⇒ Object
-
#initialize(archive, empty: false) ⇒ Archive
constructor
A new instance of Archive.
Constructor Details
#initialize(archive, empty: false) ⇒ Archive
Returns a new instance of Archive.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mixlib/archive.rb', line 18 def initialize(archive, empty: false) @empty = empty archive = File.(archive) begin # we prefer to use libarchive, which supports a great big pile o' stuff require_relative "archive/lib_archive" @archiver = Mixlib::Archive::LibArchive.new(archive) rescue LoadError # but if we can't use that, we'll fall back to ruby's native tar implementation @archiver = Mixlib::Archive::Tar.new(archive) end end |
Instance Attribute Details
#archiver ⇒ Object (readonly) Also known as: extractor
Returns the value of attribute archiver.
10 11 12 |
# File 'lib/mixlib/archive.rb', line 10 def archiver @archiver end |
Class Method Details
.archive_directory(path, archive, gzip: false, format: :tar, compression: :none) ⇒ Object
13 14 15 16 |
# File 'lib/mixlib/archive.rb', line 13 def self.archive_directory(path, archive, gzip: false, format: :tar, compression: :none) targets = Find.find(path).collect { |fn| fn } new(archive).create(targets, gzip: gzip) end |
Instance Method Details
#create(files = [], gzip: false) ⇒ Object
38 39 40 |
# File 'lib/mixlib/archive.rb', line 38 def create(files = [], gzip: false) archiver.create(files, gzip: gzip) end |
#extract(destination, perms: true, ignore: []) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/mixlib/archive.rb', line 42 def extract(destination, perms: true, ignore: []) ignore = [/^\.$/, /\.{2}#{path_separator}/] + Array(ignore) create_and_empty(destination) archiver.extract(destination, perms: perms, ignore: ignore) end |