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
# 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
  skip_resource 'The `registry_key` resource is not supported on your OS yet.'
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



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

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)


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

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

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

Returns:

  • (Boolean)


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

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)


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

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)


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

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

#to_sObject



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

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