Class: Inspec::Resources::RegistryKey

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

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.



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

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



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

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.



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

def reg_key
  @reg_key
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


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

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

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

Returns:

  • (Boolean)


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

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)


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

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)


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

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

#to_sObject



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

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