Class: PuppetX::Puppetlabs::Registry::RegistryValuePath Private

Inherits:
RegistryPathBase
  • Object
show all
Defined in:
lib/puppet_x/puppetlabs/registry.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Attributes inherited from RegistryPathBase

#path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RegistryPathBase

#access, #aliases, #ascend, #root, #subkey, #valid?

Constructor Details

#initialize(path) ⇒ RegistryValuePath

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Extract the valuename from the path and then munge the actual path

Raises:

  • (ArgumentError)


183
184
185
186
187
188
189
190
191
192
193
# File 'lib/puppet_x/puppetlabs/registry.rb', line 183

def initialize(path)
  raise ArgumentError, "Invalid registry key: #{path}" unless path.include?('\\')

  # valuename appears after the the first double backslash
  path, @valuename = path.split('\\\\', 2)
  # no \\ but there is at least a single \ to split on
  path, _, @valuename = path.rpartition('\\') if @valuename.nil?
  @is_default = @valuename.empty?

  super(path)
end

Instance Attribute Details

#valuenameObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



167
168
169
# File 'lib/puppet_x/puppetlabs/registry.rb', line 167

def valuename
  @valuename
end

Class Method Details

.combine_path_and_value(keypath, valuename) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Combines a registry key path and valuename into a resource title for registry_value resource.

To maintain backwards compatibility, only use the double backslash delimiter if the valuename actually contains a backslash



174
175
176
177
178
179
180
# File 'lib/puppet_x/puppetlabs/registry.rb', line 174

def self.combine_path_and_value(keypath, valuename)
  if valuename.include?('\\')
    "#{keypath}\\\\#{valuename}"
  else
    "#{keypath}\\#{valuename}"
  end
end

Instance Method Details

#canonicalObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



195
196
197
198
199
200
201
202
203
# File 'lib/puppet_x/puppetlabs/registry.rb', line 195

def canonical
  # Because we extracted the valuename in the initializer we
  # need to add it back in when canonical is called.
  if valuename.include?('\\')
    "#{filter_path[:canonical]}\\\\#{valuename}"
  else
    "#{filter_path[:canonical]}\\#{valuename}"
  end
end

#default?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


205
206
207
# File 'lib/puppet_x/puppetlabs/registry.rb', line 205

def default?
  @is_default
end

#filter_pathObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

  • (ArgumentError)


209
210
211
212
213
214
215
216
217
# File 'lib/puppet_x/puppetlabs/registry.rb', line 209

def filter_path
  result = super

  # It's possible to pass in a path of 'hklm' which can still be parsed, but is not valid registry key.  Only the default value 'hklm\'
  # and named values 'hklm\something' are allowed
  raise ArgumentError, "Invalid registry key: #{path}" if result[:trailing_path].empty? && valuename.empty? && !default?

  result
end