Class: Inspec::Resources::ChocoPkg

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(package_name, _opts = {}) ⇒ ChocoPkg

Returns a new instance of ChocoPkg.



21
22
23
24
25
26
# File 'lib/inspec/resources/chocolatey_package.rb', line 21

def initialize(package_name, _opts = {})
  raise "Chocolatey is not installed" unless inspec.command("choco").exist?

  @package_name = package_name
  @cache = base_data.update(generate_cache)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/inspec/resources/chocolatey_package.rb', line 40

def method_missing(method_name, *args, &block)
  if @cache.key?(method_name)
    @cache.fetch(method_name)
  else
    super
  end
end

Instance Attribute Details

#package_nameObject (readonly)

Returns the value of attribute package_name.



19
20
21
# File 'lib/inspec/resources/chocolatey_package.rb', line 19

def package_name
  @package_name
end

Instance Method Details

#infoObject



32
33
34
# File 'lib/inspec/resources/chocolatey_package.rb', line 32

def info
  @cache.dup
end

#installed?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/inspec/resources/chocolatey_package.rb', line 28

def installed?
  @cache[:installed]
end

#resource_idObject



48
49
50
# File 'lib/inspec/resources/chocolatey_package.rb', line 48

def resource_id
  @package_name || "chocolatey_package"
end

#respond_to_missing?(method_name) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/inspec/resources/chocolatey_package.rb', line 36

def respond_to_missing?(method_name, *)
  @cache.key?(method_name) || super
end

#to_sObject



52
53
54
# File 'lib/inspec/resources/chocolatey_package.rb', line 52

def to_s
  "Chocolatey package #{package_name}"
end