Class: Inspec::Requirement
- Inherits:
-
Object
- Object
- Inspec::Requirement
- Defined in:
- lib/inspec/dependencies/requirement.rb
Overview
Inspec::Requirement represents a given profile dependency, where appropriate we delegate to Inspec::Profile directly.
Instance Attribute Summary collapse
-
#cwd ⇒ Object
readonly
Returns the value of attribute cwd.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#required_version ⇒ Object
readonly
Returns the value of attribute required_version.
Class Method Summary collapse
- .from_lock_entry(entry, cwd, cache, backend, opts = {}) ⇒ Object
- .from_metadata(dep, cache, opts) ⇒ Object
Instance Method Summary collapse
-
#dependencies ⇒ Object
load dependencies of the dependency.
- #fetcher ⇒ Object
- #gem_dep ⇒ Object
-
#initialize(name, version_constraints, cache, cwd, opts) ⇒ Requirement
constructor
A new instance of Requirement.
- #lock_deps(dep_array) ⇒ Object
-
#name ⇒ Object
A dependency can be renamed in inspec.yml/inspec.lock.
-
#profile ⇒ Object
load the profile for the requirement.
- #resolved_source ⇒ Object
- #source_satisfies_spec? ⇒ Boolean
- #source_version ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, version_constraints, cache, cwd, opts) ⇒ Requirement
Returns a new instance of Requirement.
33 34 35 36 37 38 39 40 |
# File 'lib/inspec/dependencies/requirement.rb', line 33 def initialize(name, version_constraints, cache, cwd, opts) @name = name @required_version = Gem::Requirement.new(Array(version_constraints)) @cache = cache @backend = opts[:backend] @opts = opts @cwd = cwd end |
Instance Attribute Details
#cwd ⇒ Object (readonly)
Returns the value of attribute cwd.
32 33 34 |
# File 'lib/inspec/dependencies/requirement.rb', line 32 def cwd @cwd end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
32 33 34 |
# File 'lib/inspec/dependencies/requirement.rb', line 32 def opts @opts end |
#required_version ⇒ Object (readonly)
Returns the value of attribute required_version.
32 33 34 |
# File 'lib/inspec/dependencies/requirement.rb', line 32 def required_version @required_version end |
Class Method Details
.from_lock_entry(entry, cwd, cache, backend, opts = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/inspec/dependencies/requirement.rb', line 17 def self.from_lock_entry(entry, cwd, cache, backend, opts = {}) req = new(entry[:name], entry[:version_constraints], cache, cwd, entry[:resolved_source].merge(backend: backend).merge(opts)) locked_deps = [] Array(entry[:dependencies]).each do |dep_entry| locked_deps << Inspec::Requirement.from_lock_entry(dep_entry, cwd, cache, backend, opts) end req.lock_deps(locked_deps) req end |
.from_metadata(dep, cache, opts) ⇒ Object
12 13 14 15 |
# File 'lib/inspec/dependencies/requirement.rb', line 12 def self.(dep, cache, opts) raise 'Cannot load empty dependency.' if dep.nil? || dep.empty? new(dep[:name], dep[:version], cache, opts[:cwd], opts.merge(dep)) end |
Instance Method Details
#dependencies ⇒ Object
load dependencies of the dependency
89 90 91 92 93 |
# File 'lib/inspec/dependencies/requirement.rb', line 89 def dependencies @dependencies ||= profile..dependencies.map do |r| Inspec::Requirement.(r, @cache, cwd: @cwd, backend: @backend) end end |
#fetcher ⇒ Object
84 85 86 |
# File 'lib/inspec/dependencies/requirement.rb', line 84 def fetcher @fetcher ||= Inspec::CachedFetcher.new(opts, @cache) end |
#gem_dep ⇒ Object
58 59 60 |
# File 'lib/inspec/dependencies/requirement.rb', line 58 def gem_dep @gem_dep ||= Gem::Dependency.new(profile.name, required_version, :runtime) end |
#lock_deps(dep_array) ⇒ Object
80 81 82 |
# File 'lib/inspec/dependencies/requirement.rb', line 80 def lock_deps(dep_array) @dependencies = dep_array end |
#name ⇒ Object
A dependency can be renamed in inspec.yml/inspec.lock. Prefer the name the user gave this dependency over the profile name.
46 47 48 |
# File 'lib/inspec/dependencies/requirement.rb', line 46 def name @name || profile.name end |
#profile ⇒ Object
load the profile for the requirement
100 101 102 103 104 105 106 107 108 |
# File 'lib/inspec/dependencies/requirement.rb', line 100 def profile return @profile if ! @profile.nil? opts = @opts.dup opts[:backend] = @backend if !@dependencies.nil? opts[:dependencies] = Inspec::DependencySet.from_array(@dependencies, @cwd, @cache, @backend) end @profile = Inspec::Profile.for_fetcher(fetcher, opts) end |
#resolved_source ⇒ Object
62 63 64 |
# File 'lib/inspec/dependencies/requirement.rb', line 62 def resolved_source @resolved_source ||= fetcher.resolved_source end |
#source_satisfies_spec? ⇒ Boolean
54 55 56 |
# File 'lib/inspec/dependencies/requirement.rb', line 54 def source_satisfies_spec? gem_dep.match?(profile.name, profile.version) end |
#source_version ⇒ Object
50 51 52 |
# File 'lib/inspec/dependencies/requirement.rb', line 50 def source_version profile.version end |
#to_hash ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/inspec/dependencies/requirement.rb', line 66 def to_hash h = { 'name' => name, 'resolved_source' => resolved_source, 'version_constraints' => required_version.to_s, } if !dependencies.empty? h['dependencies'] = dependencies.map(&:to_hash) end h end |
#to_s ⇒ Object
95 96 97 |
# File 'lib/inspec/dependencies/requirement.rb', line 95 def to_s name end |