Class: Inspec::Targets::ZipHelper

Inherits:
ArchiveHelper show all
Defined in:
lib/inspec/targets/zip.rb

Instance Method Summary collapse

Methods inherited from ArchiveHelper

#resolve

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
# 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 = {
        content: io.read,
        type: opts[:as] || :test,
        # ref: File.join(input, entry.name),
      }
      content.push(h)
    end
  end
  content
end

#handles?(target) ⇒ Boolean

Returns:

  • (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



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/inspec/targets/zip.rb', line 31

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_sObject



48
49
50
# File 'lib/inspec/targets/zip.rb', line 48

def to_s
  'zip Loader'
end