Module: IMW::Resources::Archive
- Included in:
- IMW::Resources::Archives::Rar, IMW::Resources::Archives::Tar, IMW::Resources::Archives::Tarbz2, IMW::Resources::Archives::Targz, IMW::Resources::Archives::Zip
- Defined in:
- lib/imw/resources/archive.rb
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) ⇒ Object
Append to this archive the given
input_paths
. -
#contents ⇒ Array
Return a (sorted) list of contents in this archive.
-
#create(*input_paths) ⇒ Object
Create an archive of the given
input_paths
. -
#extract ⇒ Object
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.
20 21 22 |
# File 'lib/imw/resources/archive.rb', line 20 def archive_settings @archive_settings end |
Instance Method Details
#append(*input_paths) ⇒ Object
Append to this archive the given input_paths
.
41 42 43 44 45 |
# File 'lib/imw/resources/archive.rb', line 41 def append *input_paths should_have_archive_setting!("Cannot append to archive #{path}", :append) IMW.system archive_settings[:program], archive_settings[:append], path, *input_paths.flatten self end |
#contents ⇒ Array
Return a (sorted) list of contents in this archive.
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/imw/resources/archive.rb', line 58 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) ⇒ Object
Create an archive of the given input_paths
.
32 33 34 35 36 |
# File 'lib/imw/resources/archive.rb', line 32 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 ⇒ Object
Extract the files from this archive to the current directory.
48 49 50 51 52 53 |
# File 'lib/imw/resources/archive.rb', line 48 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 end |
#is_archive? ⇒ true, false
Is this file an archive?
25 26 27 |
# File 'lib/imw/resources/archive.rb', line 25 def is_archive? true end |