Class: Inspec::Resources::WindowsFeature

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

Instance Method Summary collapse

Constructor Details

#initialize(feature, method = nil) ⇒ WindowsFeature

Returns a new instance of WindowsFeature.



28
29
30
31
32
# File 'lib/inspec/resources/windows_feature.rb', line 28

def initialize(feature, method = nil)
  @feature = feature
  @method = method
  @cache = nil
end

Instance Method Details

#infoObject

returns the package description



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/inspec/resources/windows_feature.rb', line 40

def info
  return @cache unless @cache.nil?

  case @method
  when :powershell
    @cache = info_via_powershell(@feature)
    if @cache[:error]
      # TODO: Allow handling `Inspec::Exception` outside of initialize
      # See: https://github.com/inspec/inspec/issues/3237
      # The below will fail the resource regardless of what is raised
      raise Inspec::Exceptions::ResourceFailed, @cache[:error]
    end
  when :dism
    @cache = info_via_dism(@feature)
  else
    @cache = info_via_powershell(@feature)
    @cache = info_via_dism(@feature) if @cache[:error]
  end

  @cache
end

#installed?Boolean

returns true if the package is installed

Returns:

  • (Boolean)


35
36
37
# File 'lib/inspec/resources/windows_feature.rb', line 35

def installed?
  info[:installed] == true
end

#to_sObject



62
63
64
# File 'lib/inspec/resources/windows_feature.rb', line 62

def to_s
  "Windows Feature '#{@feature}'"
end