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.
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_array(dependencies, cwd, cache, backend) ⇒ Object
- 
  
    
      .from_lockfile(lockfile, cwd, cache, backend, opts = {})  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Return a dependency set given a lockfile. 
Instance Method Summary collapse
- #each ⇒ Object
- 
  
    
      #initialize(cwd, cache, dep_list, backend)  ⇒ dependencies 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    initialize. 
- #list ⇒ Object
- #to_array ⇒ Object
- 
  
    
      #vendor(dependencies)  ⇒ nil 
    
    
  
  
  
  
  
  
  
  
  
    1. 
Constructor Details
#initialize(cwd, cache, dep_list, backend) ⇒ dependencies
initialize
| 56 57 58 59 60 61 | # File 'lib/inspec/dependencies/dependency_set.rb', line 56 def initialize(cwd, cache, dep_list, backend) @cwd = cwd @cache = cache @dep_list = dep_list @backend = backend end | 
Instance Attribute Details
#dep_list=(value) ⇒ Object (writeonly)
Sets the attribute dep_list
| 50 51 52 | # File 'lib/inspec/dependencies/dependency_set.rb', line 50 def dep_list=(value) @dep_list = value end | 
#vendor_path ⇒ Object (readonly)
Returns the value of attribute vendor_path.
| 49 50 51 | # File 'lib/inspec/dependencies/dependency_set.rb', line 49 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.
| 40 41 42 43 44 45 46 47 | # File 'lib/inspec/dependencies/dependency_set.rb', line 40 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_array(dependencies, cwd, cache, backend) ⇒ Object
| 26 27 28 29 30 31 32 | # File 'lib/inspec/dependencies/dependency_set.rb', line 26 def self.from_array(dependencies, cwd, cache, backend) dep_list = {} dependencies.each do |d| dep_list[d.name] = d end new(cwd, cache, dep_list, backend) end | 
.from_lockfile(lockfile, cwd, cache, backend, opts = {}) ⇒ Object
Return a dependency set given a lockfile.
| 17 18 19 20 21 22 23 24 | # File 'lib/inspec/dependencies/dependency_set.rb', line 17 def self.from_lockfile(lockfile, cwd, cache, backend, opts = {}) dep_tree = lockfile.deps.map do |dep| Inspec::Requirement.from_lock_entry(dep, cwd, cache, backend, opts) end dep_list = flatten_dep_tree(dep_tree) new(cwd, cache, dep_list, backend) end | 
Instance Method Details
#each ⇒ Object
| 63 64 65 66 67 | # File 'lib/inspec/dependencies/dependency_set.rb', line 63 def each @dep_list.each do |_k, v| yield v.profile end end | 
#list ⇒ Object
| 69 70 71 | # File 'lib/inspec/dependencies/dependency_set.rb', line 69 def list @dep_list || {} end | 
#to_array ⇒ Object
| 73 74 75 76 77 78 | # File 'lib/inspec/dependencies/dependency_set.rb', line 73 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 
| 87 88 89 90 | # File 'lib/inspec/dependencies/dependency_set.rb', line 87 def vendor(dependencies) return nil if dependencies.nil? || dependencies.empty? @dep_list = Resolver.resolve(dependencies, @cache, @cwd, @backend) end |