Module: IMW::Archives::Base
Overview
Defines methods for creating, appending to, extracting, and listing an archive file. This module isn’t used to directly extend an IMW::Resource – instead, format specifc modules (e.g. - IMW::Resources::Archives::Tarbz2) include this module and define the specific settings (command-line flags, &c.) required to make things work.
Instance Attribute Summary collapse
-
#archive_settings ⇒ Object
Returns the value of attribute archive_settings.
Instance Method Summary collapse
-
#append(*input_paths) ⇒ IMW::Resource
Append to this archive the given
input_paths
. -
#contents ⇒ Array<String>
Return a (sorted) list of contents in this archive.
-
#create(*input_paths) ⇒ IMW::Resource
Create an archive of the given
input_paths
. -
#extract ⇒ IMW::Resource
Extract the files from this archive to the current directory.
-
#is_archive? ⇒ true, false
Is this file an archive?.
Instance Attribute Details
#archive_settings ⇒ Object
Returns the value of attribute archive_settings.
31 32 33 |
# File 'lib/imw/archives.rb', line 31 def archive_settings @archive_settings end |
Instance Method Details
#append(*input_paths) ⇒ IMW::Resource
Append to this archive the given input_paths
.
The input paths must be strings and will be shell-escaped before further processing. This means you cannot use a shell glob!
62 63 64 65 66 |
# File 'lib/imw/archives.rb', line 62 def append *input_paths should_have_archive_setting!("Cannot append to archive #{path}", :program, :append) IMW.system archive_settings[:program], archive_settings[:append], path, *input_paths.flatten self end |
#contents ⇒ Array<String>
Return a (sorted) list of contents in this archive.
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/imw/archives.rb', line 82 def contents should_exist!("Cannot list archive contents.") should_have_archive_setting!("Cannot list archive #{path}", :list, [:unarchiving_program, :program]) program = archive_settings[:unarchiving_program] || archive_settings[:program] # FIXME this needs to be more robust flags = archive_settings[:list] flags = flags.join(' ') if flags.is_a?(Array) command = [program, flags, path.gsub(' ', '\ ')].join(' ') output = `#{command}` archive_contents_string_to_array(output) end |
#create(*input_paths) ⇒ IMW::Resource
Create an archive of the given input_paths
.
The input paths must be strings and will be shell-escaped before further processing. This means you cannot use a shell glob!
48 49 50 51 52 |
# File 'lib/imw/archives.rb', line 48 def create *input_paths should_have_archive_setting!("Cannot create archive #{path}", :program, :create) IMW.system archive_settings[:program], archive_settings[:create], path, *input_paths.flatten self end |
#extract ⇒ IMW::Resource
Extract the files from this archive to the current directory.
71 72 73 74 75 76 77 |
# File 'lib/imw/archives.rb', line 71 def extract should_exist!("Cannot extract archive.") should_have_archive_setting!("Cannot extract archive #{path}", :extract, [:unarchving_program, :program]) program = archive_settings[:unarchiving_program] || archive_settings[:program] IMW.system program, archive_settings[:extract], path self end |
#is_archive? ⇒ true, false
Is this file an archive?
36 37 38 |
# File 'lib/imw/archives.rb', line 36 def is_archive? true end |