Class: RegistryKey

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

Overview

Usage: describe registry_key(‘Task Scheduler’,‘HKEY_LOCAL_MACHINESYSTEMCurrentControlSetservicesSchedule’) do

its('Start') { should eq 2 }

end

Direct Known Subclasses

WindowsRegistryKey

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, reg_key = nil) ⇒ RegistryKey

Returns a new instance of RegistryKey.



24
25
26
27
28
29
30
31
# File 'lib/resources/registry_key.rb', line 24

def initialize(name, reg_key = nil)
  # if we have one parameter, we use it as name
  reg_key ||= name
  @name = name
  @reg_key = reg_key

  return skip_resource 'The `registry_key` resource is not supported on your OS yet.' if !inspec.os.windows?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth) ⇒ Object

returns nil, if not existant or value



60
61
62
63
64
# File 'lib/resources/registry_key.rb', line 60

def method_missing(meth)
  # get data
  val = registry_key(@reg_key)
  registry_property_value(val, meth)
end

Instance Attribute Details

#reg_keyObject

Returns the value of attribute reg_key.



22
23
24
# File 'lib/resources/registry_key.rb', line 22

def reg_key
  @reg_key
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


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

def exists?
  !registry_key(@reg_key).nil?
end

#has_property?(property_name, property_type = nil) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
# File 'lib/resources/registry_key.rb', line 42

def has_property?(property_name, property_type = nil)
  val = registry_key(@reg_key)
  !val.nil? && registry_property_exists(val, property_name) && (property_type.nil? || registry_property_type(val, property_name) == map2type(property_type)) ? true : false
end

#has_property_value?(property_name, property_type = nil, value) ⇒ Boolean

deactivate rubocop, because we need to stay compatible with Serverspe rubocop:disable Style/OptionalArguments

Returns:

  • (Boolean)


49
50
51
52
53
54
55
56
57
# File 'lib/resources/registry_key.rb', line 49

def has_property_value?(property_name, property_type = nil, value)
  # rubocop:enable Style/OptionalArguments
  val = registry_key(@reg_key)

  # convert value to binary if required
  value = value.bytes if !property_type.nil? && map2type(property_type) == 3 && !value.is_a?(Array)

  !val.nil? && registry_property_value(val, property_name) == value && (property_type.nil? || registry_property_type(val, property_name) == map2type(property_type)) ? true : false
end

#has_value?(value) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
# File 'lib/resources/registry_key.rb', line 37

def has_value?(value)
  val = registry_key(@reg_key)
  !val.nil? && registry_property_value(val, '(default)') == value ? true : false
end

#to_sObject



66
67
68
# File 'lib/resources/registry_key.rb', line 66

def to_s
  "Registry Key #{@name}"
end