Class: SourceReaders::GemReader

Inherits:
Object
  • Object
show all
Defined in:
lib/source_readers/gem.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ GemReader

This creates a new instance of an InSpec Gem-packaged profile source reader As of July 2024 only resource packs, not controls, may be packaged as gems

Parameters:

  • target (FileProvider)

    An instance of a FileProvider object that can list files and read them



25
26
27
28
29
30
31
32
# File 'lib/source_readers/gem.rb', line 25

def initialize(target)
  @target     = target
  @metadata   = (target.files.grep("inspec.yml").first)
  @tests      = {} # TODO - one day support controls?
  @libraries  = load_libs
  @data_files = {}
  @readme     = load_readme
end

Instance Attribute Details

#data_filesObject (readonly)

Returns the value of attribute data_files.



19
20
21
# File 'lib/source_readers/gem.rb', line 19

def data_files
  @data_files
end

#librariesObject (readonly)

Returns the value of attribute libraries.



19
20
21
# File 'lib/source_readers/gem.rb', line 19

def libraries
  @libraries
end

#metadataObject (readonly)

Returns the value of attribute metadata.



19
20
21
# File 'lib/source_readers/gem.rb', line 19

def 
  @metadata
end

#metadata_srcObject (readonly)

Returns the value of attribute metadata_src.



19
20
21
# File 'lib/source_readers/gem.rb', line 19

def 
  @metadata_src
end

#readmeObject (readonly)

Returns the value of attribute readme.



19
20
21
# File 'lib/source_readers/gem.rb', line 19

def readme
  @readme
end

#targetObject (readonly)

Returns the value of attribute target.



19
20
21
# File 'lib/source_readers/gem.rb', line 19

def target
  @target
end

#testsObject (readonly)

Returns the value of attribute tests.



19
20
21
# File 'lib/source_readers/gem.rb', line 19

def tests
  @tests
end

Class Method Details

.resolve(target) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/source_readers/gem.rb', line 9

def self.resolve(target)
  # Only match if gemspec is at root level, not in vendor directories
  # This prevents archived/vendored profiles from being treated as gem profiles
  gemspec_files = target.files.grep(/gemspec/)
  root_gemspec = gemspec_files.reject { |f| f.start_with?("vendor/") }
  return new(target) unless root_gemspec.empty?

  nil
end