Class: Inspec::Resources::RegistryKey
- Inherits:
-
Object
- Object
- Inspec::Resources::RegistryKey
- Defined in:
- lib/resources/registry_key.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#reg_key ⇒ Object
Returns the value of attribute reg_key.
Instance Method Summary collapse
- #exists? ⇒ Boolean
- #has_property?(property_name, property_type = nil) ⇒ Boolean
-
#has_property_value?(property_name, property_type = nil, value) ⇒ Boolean
deactivate rubocop, because we need to stay compatible with Serverspe rubocop:disable Style/OptionalArguments.
- #has_value?(value) ⇒ Boolean
-
#initialize(name, reg_key = nil) ⇒ RegistryKey
constructor
A new instance of RegistryKey.
-
#method_missing(meth) ⇒ Object
returns nil, if not existant or value.
- #to_s ⇒ Object
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_key ⇒ Object
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
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
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
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
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_s ⇒ Object
67 68 69 |
# File 'lib/resources/registry_key.rb', line 67 def to_s "Registry Key #{@name}" end |