Class: Inspec::Resources::ChocoPkg

Inherits:
Object
  • Object
show all
Defined in:
lib/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.



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

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



37
38
39
40
41
42
43
# File 'lib/resources/chocolatey_package.rb', line 37

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.



17
18
19
# File 'lib/resources/chocolatey_package.rb', line 17

def package_name
  @package_name
end

Instance Method Details

#infoObject



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

def info
  @cache.dup
end

#installed?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/resources/chocolatey_package.rb', line 25

def installed?
  @cache[:installed]
end

#respond_to_missing?(method_name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#to_sObject



45
46
47
# File 'lib/resources/chocolatey_package.rb', line 45

def to_s
  "Chocolatey package #{package_name}"
end