Class: Inspec::Requirement
- Inherits:
-
Object
- Object
- Inspec::Requirement
- Defined in:
- lib/inspec/dependencies.rb
Instance Attribute Summary collapse
-
#cwd ⇒ Object
readonly
Returns the value of attribute cwd.
-
#dep ⇒ Object
readonly
Returns the value of attribute dep.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, dep, cwd, opts) ⇒ Requirement
constructor
A new instance of Requirement.
- #matches_spec?(spec) ⇒ Boolean
- #path ⇒ Object
- #profile ⇒ Object
- #pull ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, dep, cwd, opts) ⇒ Requirement
213 214 215 216 217 218 |
# File 'lib/inspec/dependencies.rb', line 213 def initialize(name, dep, cwd, opts) @name = name @dep = Gem::Dependency.new(name, Gem::Requirement.new(Array(dep)), :runtime) @opts = opts @cwd = cwd end |
Instance Attribute Details
#cwd ⇒ Object (readonly)
Returns the value of attribute cwd.
212 213 214 |
# File 'lib/inspec/dependencies.rb', line 212 def cwd @cwd end |
#dep ⇒ Object (readonly)
Returns the value of attribute dep.
212 213 214 |
# File 'lib/inspec/dependencies.rb', line 212 def dep @dep end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
212 213 214 |
# File 'lib/inspec/dependencies.rb', line 212 def name @name end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
212 213 214 |
# File 'lib/inspec/dependencies.rb', line 212 def opts @opts end |
Class Method Details
.from_metadata(dep, opts) ⇒ Object
243 244 245 246 247 248 |
# File 'lib/inspec/dependencies.rb', line 243 def self.(dep, opts) fail 'Cannot load empty dependency.' if dep.nil? || dep.empty? name = dep[:name] || fail('You must provide a name for all dependencies') version = dep[:version] new(name, version, opts[:cwd], dep) end |
Instance Method Details
#matches_spec?(spec) ⇒ Boolean
220 221 222 223 |
# File 'lib/inspec/dependencies.rb', line 220 def matches_spec?(spec) params = spec.profile..params @dep.match?(params[:name], params[:version]) end |
#path ⇒ Object
234 235 236 |
# File 'lib/inspec/dependencies.rb', line 234 def path @path || pull end |
#profile ⇒ Object
238 239 240 241 |
# File 'lib/inspec/dependencies.rb', line 238 def profile return nil if path.nil? @profile ||= Inspec::Profile.for_target(path, {}) end |
#pull ⇒ Object
225 226 227 228 229 230 231 232 |
# File 'lib/inspec/dependencies.rb', line 225 def pull case when @opts[:path] then pull_path(@opts[:path]) else # TODO: should default to supermarket fail 'You must specify the source of the dependency (for now...)' end end |
#to_s ⇒ Object
250 251 252 |
# File 'lib/inspec/dependencies.rb', line 250 def to_s @dep.to_s end |