class Chef::Resource::ChocolateyConfig
Public Instance Methods
choco_cmd(action)
click to toggle source
@param [String] action the name of the action to perform @return [String] the choco config command string
# File lib/chef/resource/chocolatey_config.rb, line 74 def choco_cmd(action) cmd = "#{ENV['ALLUSERSPROFILE']}\\chocolatey\\bin\\choco config #{action} --name #{new_resource.config_key}" cmd << " --value #{new_resource.value}" if action == "set" cmd end
fetch_config_element(id)
click to toggle source
@param [String] id the config name @return [String] the element's value field
# File lib/chef/resource/chocolatey_config.rb, line 41 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