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



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

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



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

def info
  @cache.dup
end

#installed?Boolean

Returns:

  • (Boolean)


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

def installed?
  @cache[:installed]
end

#respond_to_missing?(method_name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#to_sObject



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

def to_s
  "Chocolatey package #{package_name}"
end