Class: Inspec::VendorIndex
- Inherits:
-
Object
- Object
- Inspec::VendorIndex
- Defined in:
- lib/inspec/dependencies/vendor_index.rb
Overview
VendorIndex manages an on-disk cache of inspec profiles. The cache can contain:
- .tar.gz profile archives
- .zip profile archives
- unpacked profiles
Cache entries names include a hash of their source to prevent conflicts between depenedencies with the same name from different sources.
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #add(name, source, path_from) ⇒ Object
- #archive_entry_for(name, source_url) ⇒ Object
-
#base_path_for(name, source_url) ⇒ String
Return the path to given profile in the vendor index.
-
#exists?(name, source_url) ⇒ Boolean
For a given name and source_url, return true if the profile exists in the VendorIndex.
-
#initialize(path = nil) ⇒ VendorIndex
constructor
A new instance of VendorIndex.
- #prefered_entry_for(name, source_url) ⇒ Object
Constructor Details
#initialize(path = nil) ⇒ VendorIndex
Returns a new instance of VendorIndex.
21 22 23 24 |
# File 'lib/inspec/dependencies/vendor_index.rb', line 21 def initialize(path = nil) @path = path || File.join(Dir.home, '.inspec', 'cache') FileUtils.mkdir_p(@path) unless File.directory?(@path) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
20 21 22 |
# File 'lib/inspec/dependencies/vendor_index.rb', line 20 def path @path end |
Instance Method Details
#add(name, source, path_from) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/inspec/dependencies/vendor_index.rb', line 26 def add(name, source, path_from) path_to = base_path_for(name, source) path_to = if File.directory?(path_to) path_to elsif path_from.end_with?('.zip') "#{path_to}.tar.gz" elsif path_from.end_with?('.tar.gz') "#{path_to}.tar.gz" else fail "Cannot add unknown archive #{path} to vendor index" end FileUtils.cp_r(path_from, path_to) path_to end |
#archive_entry_for(name, source_url) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/inspec/dependencies/vendor_index.rb', line 50 def archive_entry_for(name, source_url) path = base_path_for(name, source_url) if File.exist?("#{path}.tar.gz") "#{path}.tar.gz" elsif File.exist?("#{path}.zip") "#{path}.zip" end end |
#base_path_for(name, source_url) ⇒ String
Return the path to given profile in the vendor index.
The ‘source_url` parameter should be a URI-like string that fully specifies the source of the exact version we want to pull down.
83 84 85 |
# File 'lib/inspec/dependencies/vendor_index.rb', line 83 def base_path_for(name, source_url) File.join(@path, key_for(name, source_url)) end |
#exists?(name, source_url) ⇒ Boolean
For a given name and source_url, return true if the profile exists in the VendorIndex.
67 68 69 70 |
# File 'lib/inspec/dependencies/vendor_index.rb', line 67 def exists?(name, source_url) path = base_path_for(name, source_url) File.directory?(path) || File.exist?("#{path}.tar.gz") || File.exist?("#{path}.zip") end |
#prefered_entry_for(name, source_url) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/inspec/dependencies/vendor_index.rb', line 41 def prefered_entry_for(name, source_url) path = base_path_for(name, source_url) if File.directory?(path) path else archive_entry_for(name, source_url) end end |