Class: Inspec::Targets::DirsResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/targets/dir.rb

Overview

Base class for all directory resolvers. I.e. any target helper that takes a directory/archive/… and ultimately calls DirsHelper to resolve it.

These resolvers must implement the required methods of this class.

Direct Known Subclasses

ArchiveHelper, FolderHelper

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.__collect(handler, getter, files) ⇒ Object



67
68
69
70
# File 'lib/inspec/targets/dir.rb', line 67

def self.__collect(handler, getter, files)
  return [] unless handler.respond_to? getter
  handler.method(getter).call(files)
end

.from_target(target) ⇒ Object



43
44
45
# File 'lib/inspec/targets/dir.rb', line 43

def self.from_target(target)
  new(target)
end

.resolve(target, opts) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/inspec/targets/dir.rb', line 47

def self.resolve(target, opts)
  r = new(target, opts)
  handler = r.handler
  files = r.files

  res = []
  {
    test:     __collect(handler, :get_filenames, files),
    library:  __collect(handler, :get_libraries, files),
    metadata: __collect(handler, :get_metadata, files),
  }.each do |as, list|
    Array(list).each { |path|
      res.push(r.resolve(path, as: as))
    }
  end

  return handler.resolve_contents(res) if handler.respond_to?(:resolve_contents)
  res
end

Instance Method Details

#filesObject



30
31
32
# File 'lib/inspec/targets/dir.rb', line 30

def files
  fail NotImplementedError, "Directory resolver #{self.class} must implement #files"
end

#handlerObject



38
39
40
41
# File 'lib/inspec/targets/dir.rb', line 38

def handler
  DirsHelper.get_handler(files) ||
    fail("Don't know how to handle #{self}")
end

#resolve(_path) ⇒ Object



34
35
36
# File 'lib/inspec/targets/dir.rb', line 34

def resolve(_path)
  fail NotImplementedError, "Directory resolver #{self.class} must implement #content"
end