Method: Chef::Resource::ChocolateyConfig#fetch_config_element
- Defined in:
- lib/chef/resource/chocolatey_config.rb
#fetch_config_element(id) ⇒ String
Returns the element’s value field.
60 61 62 63 64 65 66 67 68 |
# File 'lib/chef/resource/chocolatey_config.rb', line 60 def fetch_config_element(id) require "rexml/document" unless defined?(REXML::Document) config_file = "#{ENV["ALLUSERSPROFILE"]}\\chocolatey\\config\\chocolatey.config" raise "Could not find the Chocolatey config at #{config_file}!" unless ::File.exist?(config_file) contents = REXML::Document.new(::File.read(config_file)) data = REXML::XPath.first(contents, "//config/add[@key=\"#{id}\"]") data ? data.attribute("value").to_s : nil # REXML just returns nil if it can't find anything so avoid an undefined method error end |