Class: Inspec::Requirement

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/dependencies.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#cwdObject (readonly)

Returns the value of attribute cwd.



212
213
214
# File 'lib/inspec/dependencies.rb', line 212

def cwd
  @cwd
end

#depObject (readonly)

Returns the value of attribute dep.



212
213
214
# File 'lib/inspec/dependencies.rb', line 212

def dep
  @dep
end

#nameObject (readonly)

Returns the value of attribute name.



212
213
214
# File 'lib/inspec/dependencies.rb', line 212

def name
  @name
end

#optsObject (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

#pathObject



234
235
236
# File 'lib/inspec/dependencies.rb', line 234

def path
  @path || pull
end

#profileObject



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

#pullObject



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_sObject



250
251
252
# File 'lib/inspec/dependencies.rb', line 250

def to_s
  @dep.to_s
end