Class: Inspec::Resources::RegistryKey
- Inherits:
- 
      Object
      
        - Object
- Inspec::Resources::RegistryKey
 
- Defined in:
- lib/resources/registry_key.rb
Direct Known Subclasses
Instance Method Summary collapse
- 
  
    
      #children(filter = nil)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    returns an arrray of child nodes. 
- #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(*keys)  ⇒ 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.
| 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | # File 'lib/resources/registry_key.rb', line 59 def initialize(name, reg_key = nil) # if we have one parameter, we use it as name reg_key ||= name = {} if reg_key && reg_key.is_a?(Hash) = .merge!(reg_key) # generate registry_key if we do not have a regular expression [:path] = [:name] ||= [:path] else [:name] = name [: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(*keys) ⇒ Object
returns nil, if not existant or value
| 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | # File 'lib/resources/registry_key.rb', line 109 def method_missing(*keys) # allow the use of array syntax in an `its` block so that users # can use it to query for keys with . characters in them if keys.is_a?(Array) keys.shift if keys[0] == :[] key = keys.first else key = keys end # get data val = registry_key([:path]) registry_property_value(val, key) end | 
Instance Method Details
#children(filter = nil) ⇒ Object
returns an arrray of child nodes
| 104 105 106 | # File 'lib/resources/registry_key.rb', line 104 def children(filter = nil) children_keys([:path], filter) end | 
#exists? ⇒ Boolean
| 77 78 79 | # File 'lib/resources/registry_key.rb', line 77 def exists? !registry_key([:path]).nil? end | 
#has_property?(property_name, property_type = nil) ⇒ Boolean
| 86 87 88 89 | # File 'lib/resources/registry_key.rb', line 86 def has_property?(property_name, property_type = nil) val = registry_key([: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
| 93 94 95 96 97 98 99 100 101 | # File 'lib/resources/registry_key.rb', line 93 def has_property_value?(property_name, property_type = nil, value) # rubocop:enable Style/OptionalArguments val = registry_key([: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
| 81 82 83 84 | # File 'lib/resources/registry_key.rb', line 81 def has_value?(value) val = registry_key([:path]) !val.nil? && registry_property_value(val, '(default)') == value ? true : false end | 
#to_s ⇒ Object
| 124 125 126 | # File 'lib/resources/registry_key.rb', line 124 def to_s "Registry Key #{@options[:name]}" end |