Class: Inspec::Resources::RegistryKey

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

Overview

rubocop:disable Metrics/ClassLength

Direct Known Subclasses

WindowsRegistryKey

Instance Method Summary collapse

Constructor Details

#initialize(name, reg_key = nil) ⇒ RegistryKey

Returns a new instance of RegistryKey.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/resources/registry_key.rb', line 60

def initialize(name, reg_key = nil)
  # if we have one parameter, we use it as name
  reg_key ||= name
  @options = {}
  if reg_key && reg_key.is_a?(Hash)
    @options = @options.merge!(reg_key)

    # generate registry_key if we do not have a regular expression
    @options[:path] = generate_registry_key_path_from_options
    @options[:name] ||= @options[:path]
  else
    @options[:name] = name
    @options[:path] = reg_key
  end

  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



110
111
112
113
114
# File 'lib/resources/registry_key.rb', line 110

def method_missing(meth)
  # get data
  val = registry_key(@options[:path])
  registry_property_value(val, meth)
end

Instance Method Details

#children(filter = nil) ⇒ Object

returns an arrray of child nodes



105
106
107
# File 'lib/resources/registry_key.rb', line 105

def children(filter = nil)
  children_keys(@options[:path], filter)
end

#exists?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/resources/registry_key.rb', line 78

def exists?
  !registry_key(@options[:path]).nil?
end

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

Returns:

  • (Boolean)


87
88
89
90
# File 'lib/resources/registry_key.rb', line 87

def has_property?(property_name, property_type = nil)
  val = registry_key(@options[:path])
  !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)


94
95
96
97
98
99
100
101
102
# File 'lib/resources/registry_key.rb', line 94

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

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


82
83
84
85
# File 'lib/resources/registry_key.rb', line 82

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

#to_sObject



116
117
118
# File 'lib/resources/registry_key.rb', line 116

def to_s
  "Registry Key #{@options[:name]}"
end