class Inspec::Requirement
Inspec::Requirement
represents a given profile dependency, where appropriate we delegate to Inspec::Profile
directly.
Attributes
cache[R]
cwd[R]
opts[R]
version_constraints[R]
Public Class Methods
from_lock_entry(entry, config, opts = {})
click to toggle source
# File lib/inspec/dependencies/requirement.rb, line 29 def self.from_lock_entry(entry, config, opts = {}) resolved_source = entry[:resolved_source] .merge(backend: config[:backend]) .merge(opts) req = new(entry[:name], entry[:version_constraints], config, resolved_source) locked_deps = [] Array(entry[:dependencies]).each do |dep_entry| dep_config = config.dup dep_config[:parent_profile] = entry[:name] locked_deps << Inspec::Requirement.from_lock_entry(dep_entry, dep_config, opts) end req.lock_deps(locked_deps) req end
from_metadata(dep, cache, opts)
click to toggle source
# File lib/inspec/dependencies/requirement.rb, line 10 def self.from_metadata(dep, cache, opts) raise "Cannot load empty dependency." if dep.nil? || dep.empty? req_path = opts[:cwd] if dep[:path] req_path = File.expand_path(dep[:path], req_path) end config = { cache: cache, cwd: req_path, } new(dep[:name], dep[:version], config, opts.merge(dep)) end
new(name, version_constraints, config, opts)
click to toggle source
# File lib/inspec/dependencies/requirement.rb, line 50 def initialize(name, version_constraints, config, opts) @name = name @version_constraints = Array(version_constraints) @cache = config[:cache] @backend = opts[:backend] @opts = opts @cwd = config[:cwd] @parent_profile = config[:parent_profile] end
Public Instance Methods
dependencies()
click to toggle source
load dependencies of the dependency
# File lib/inspec/dependencies/requirement.rb, line 109 def dependencies @dependencies ||= profile.metadata.dependencies.map do |r| Inspec::Requirement.from_metadata(r, @cache, cwd: @cwd, backend: @backend) end end
fetcher()
click to toggle source
# File lib/inspec/dependencies/requirement.rb, line 104 def fetcher @fetcher ||= Inspec::CachedFetcher.new(opts, @cache) end
lock_deps(dep_array)
click to toggle source
# File lib/inspec/dependencies/requirement.rb, line 100 def lock_deps(dep_array) @dependencies = dep_array end
name()
click to toggle source
A dependency can be renamed in inspec.yml/inspec.lock. Prefer the name the user gave this dependency over the profile name.
# File lib/inspec/dependencies/requirement.rb, line 64 def name @name || profile.name end
profile()
click to toggle source
load the profile for the requirement
# File lib/inspec/dependencies/requirement.rb, line 120 def profile return @profile unless @profile.nil? opts = @opts.dup opts[:backend] = @backend opts[:runner_conf] = Inspec::Config.cached if !@dependencies.nil? && !@dependencies.empty? opts[:dependencies] = Inspec::DependencySet.from_array(@dependencies, @cwd, @cache, @backend) end opts[:profile_name] = @name opts[:parent_profile] = @parent_profile @profile = Inspec::Profile.for_fetcher(fetcher, opts) @profile end
resolved_source()
click to toggle source
# File lib/inspec/dependencies/requirement.rb, line 82 def resolved_source @resolved_source ||= fetcher.resolved_source end
source_satisfies_spec?()
click to toggle source
# File lib/inspec/dependencies/requirement.rb, line 72 def source_satisfies_spec? return true if version_constraints.empty? # Semverse::Constraint.satisfy_all returns a list of versions that match all of the # supplied constraints. Since we're only matching against a single version, the return # of satisfy_all will be non-empty if the profile version we have satisfies the constraints. constraints = @version_constraints.map { |x| Semverse::Constraint.new(x) } !Semverse::Constraint.satisfy_all(constraints, Semverse::Version.new(profile.version)).empty? end
source_version()
click to toggle source
# File lib/inspec/dependencies/requirement.rb, line 68 def source_version profile.version end
to_hash()
click to toggle source
# File lib/inspec/dependencies/requirement.rb, line 86 def to_hash h = { "name" => name, "resolved_source" => resolved_source, "version_constraints" => version_constraints, } unless dependencies.empty? h["dependencies"] = dependencies.map(&:to_hash) end h end
to_s()
click to toggle source
# File lib/inspec/dependencies/requirement.rb, line 115 def to_s name end