Class: Inspec::DependencySet
- Inherits:
-
Object
- Object
- Inspec::DependencySet
- Defined in:
- lib/inspec/dependencies/dependency_set.rb
Overview
A DependencySet manages a list of dependencies for a profile.
Currently this class is a thin wrapper interface to coordinate the VendorIndex and the Resolver.
Instance Attribute Summary collapse
-
#dep_list ⇒ Object
writeonly
Sets the attribute dep_list.
-
#vendor_path ⇒ Object
readonly
Returns the value of attribute vendor_path.
Class Method Summary collapse
-
.flatten_dep_tree(dep_tree) ⇒ Object
This is experimental code to test the working of the dependency loader - perform a proper dependency related search in the future.
-
.from_lockfile(lockfile, cwd, vendor_path) ⇒ Object
Return a dependency set given a lockfile.
Instance Method Summary collapse
-
#initialize(cwd, vendor_path, dep_list = nil) ⇒ dependencies
constructor
initialize.
- #list ⇒ Object
- #to_array ⇒ Object
-
#vendor(dependencies) ⇒ nil
1.
Constructor Details
#initialize(cwd, vendor_path, dep_list = nil) ⇒ dependencies
initialize
53 54 55 56 57 |
# File 'lib/inspec/dependencies/dependency_set.rb', line 53 def initialize(cwd, vendor_path, dep_list = nil) @cwd = cwd @vendor_path = vendor_path @dep_list = dep_list end |
Instance Attribute Details
#dep_list=(value) ⇒ Object (writeonly)
Sets the attribute dep_list
47 48 49 |
# File 'lib/inspec/dependencies/dependency_set.rb', line 47 def dep_list=(value) @dep_list = value end |
#vendor_path ⇒ Object (readonly)
Returns the value of attribute vendor_path.
46 47 48 |
# File 'lib/inspec/dependencies/dependency_set.rb', line 46 def vendor_path @vendor_path end |
Class Method Details
.flatten_dep_tree(dep_tree) ⇒ Object
This is experimental code to test the working of the dependency loader - perform a proper dependency related search in the future.
Flatten tree because that is all we know how to deal with for right now. Last dep seen for a given name wins right now.
37 38 39 40 41 42 43 44 |
# File 'lib/inspec/dependencies/dependency_set.rb', line 37 def self.flatten_dep_tree(dep_tree) dep_list = {} dep_tree.each do |d| dep_list[d.name] = d dep_list.merge!(flatten_dep_tree(d.dependencies)) end dep_list end |
.from_lockfile(lockfile, cwd, vendor_path) ⇒ Object
Return a dependency set given a lockfile.
21 22 23 24 25 26 27 28 29 |
# File 'lib/inspec/dependencies/dependency_set.rb', line 21 def self.from_lockfile(lockfile, cwd, vendor_path) vendor_index = VendorIndex.new(vendor_path) dep_tree = lockfile.deps.map do |dep| Inspec::Requirement.from_lock_entry(dep, cwd, vendor_index) end dep_list = flatten_dep_tree(dep_tree) new(cwd, vendor_path, dep_list) end |
Instance Method Details
#list ⇒ Object
59 60 61 |
# File 'lib/inspec/dependencies/dependency_set.rb', line 59 def list @dep_list end |
#to_array ⇒ Object
63 64 65 66 67 68 |
# File 'lib/inspec/dependencies/dependency_set.rb', line 63 def to_array return [] if @dep_list.nil? @dep_list.map do |_k, v| v.to_hash end.compact end |
#vendor(dependencies) ⇒ nil
-
Get dependencies, pull things to a local cache if necessary
-
Resolve dependencies
77 78 79 80 81 |
# File 'lib/inspec/dependencies/dependency_set.rb', line 77 def vendor(dependencies) return nil if dependencies.nil? || dependencies.empty? @vendor_index ||= VendorIndex.new(@vendor_path) @dep_list = Resolver.resolve(dependencies, @vendor_index, @cwd) end |