Class: Inspec::Targets::ZipHelper
- Inherits:
-
ArchiveHelper
- Object
- ArchiveHelper
- Inspec::Targets::ZipHelper
- Defined in:
- lib/inspec/targets/zip.rb
Instance Method Summary collapse
- #content(input, files, rootdir = nil, opts = {}) ⇒ Object
- #handles?(target) ⇒ Boolean
- #structure(input) ⇒ Object
- #to_s ⇒ Object
Methods inherited from ArchiveHelper
Instance Method Details
#content(input, files, rootdir = nil, opts = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/inspec/targets/zip.rb', line 15 def content(input, files, rootdir = nil, opts = {}) content = [] ::Zip::InputStream.open(input) do |io| while (entry = io.get_next_entry) next if !files.include?(entry.name.gsub(rootdir, '')) h = { # NB if some file is empty, return empty-string, not nil content: io.read || '', type: opts[:as] || :test, ref: entry.name, } content.push(h) end end content end |
#handles?(target) ⇒ Boolean
11 12 13 |
# File 'lib/inspec/targets/zip.rb', line 11 def handles?(target) File.file?(target) and target.end_with?('.zip') end |
#structure(input) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/inspec/targets/zip.rb', line 32 def structure(input) files = [] rootdir = '' ::Zip::InputStream.open(input) do |io| while (entry = io.get_next_entry) pn = Pathname(entry.name) rootdir = pn.dirname.to_s if pn.basename.to_s == 'inspec.yml' || pn.basename.to_s == 'metadata.rb' files.push(entry.name) end end # stores the rootdir of metadata.rb or inspec.yml rootdir += '/' if !rootdir.empty? [files, rootdir] end |
#to_s ⇒ Object
49 50 51 |
# File 'lib/inspec/targets/zip.rb', line 49 def to_s 'zip Loader' end |