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.
43 44 45 46 47 48 49 50 |
# File 'lib/inspec/dependencies/requirement.rb', line 43 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.
42 43 44 |
# File 'lib/inspec/dependencies/requirement.rb', line 42 def cwd @cwd end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
42 43 44 |
# File 'lib/inspec/dependencies/requirement.rb', line 42 def opts @opts end |
#required_version ⇒ Object (readonly)
Returns the value of attribute required_version.
42 43 44 |
# File 'lib/inspec/dependencies/requirement.rb', line 42 def required_version @required_version end |
Class Method Details
.from_lock_entry(entry, cwd, cache, backend, opts = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/inspec/dependencies/requirement.rb', line 27 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
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/inspec/dependencies/requirement.rb', line 11 def self.(dep, cache, opts) raise 'Cannot load empty dependency.' if dep.nil? || dep.empty? req_path = opts[:cwd] if dep[:path] req_path = File.(dep[:path], req_path) end new(dep[:name], dep[:version], cache, req_path, opts.merge(dep)) end |
Instance Method Details
#dependencies ⇒ Object
load dependencies of the dependency
99 100 101 102 103 |
# File 'lib/inspec/dependencies/requirement.rb', line 99 def dependencies @dependencies ||= profile..dependencies.map do |r| Inspec::Requirement.(r, @cache, cwd: @cwd, backend: @backend) end end |
#fetcher ⇒ Object
94 95 96 |
# File 'lib/inspec/dependencies/requirement.rb', line 94 def fetcher @fetcher ||= Inspec::CachedFetcher.new(opts, @cache) end |
#gem_dep ⇒ Object
68 69 70 |
# File 'lib/inspec/dependencies/requirement.rb', line 68 def gem_dep @gem_dep ||= Gem::Dependency.new(profile.name, required_version, :runtime) end |
#lock_deps(dep_array) ⇒ Object
90 91 92 |
# File 'lib/inspec/dependencies/requirement.rb', line 90 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.
56 57 58 |
# File 'lib/inspec/dependencies/requirement.rb', line 56 def name @name || profile.name end |
#profile ⇒ Object
load the profile for the requirement
110 111 112 113 114 115 116 117 118 |
# File 'lib/inspec/dependencies/requirement.rb', line 110 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
72 73 74 |
# File 'lib/inspec/dependencies/requirement.rb', line 72 def resolved_source @resolved_source ||= fetcher.resolved_source end |
#source_satisfies_spec? ⇒ Boolean
64 65 66 |
# File 'lib/inspec/dependencies/requirement.rb', line 64 def source_satisfies_spec? gem_dep.match?(profile.name, profile.version) end |
#source_version ⇒ Object
60 61 62 |
# File 'lib/inspec/dependencies/requirement.rb', line 60 def source_version profile.version end |
#to_hash ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/inspec/dependencies/requirement.rb', line 76 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
105 106 107 |
# File 'lib/inspec/dependencies/requirement.rb', line 105 def to_s name end |