class Chef::Resource::Alternatives
Public Instance Methods
alternatives_cmd()
click to toggle source
@return [String] The appropriate alternatives command based on the platform
# File lib/chef/resource/alternatives.rb, line 170 def alternatives_cmd if debian? "update-alternatives" else "alternatives" end end
current_path()
click to toggle source
@return [String] The current path for the link_name alternative
# File lib/chef/resource/alternatives.rb, line 192 def current_path # https://rubular.com/r/ylsuvzUtquRPqc match = shell_out(alternatives_cmd, "--display", new_resource.link_name).stdout.match(/link currently points to (.*)/) match[1] end
define_resource_requirements()
click to toggle source
# File lib/chef/resource/alternatives.rb, line 97 def define_resource_requirements requirements.assert(:install) do |a| a.assertion do !new_resource.priority.nil? end a.failure_message("Could not set alternatives for #{new_resource.link_name}, you must provide the :priority property") end requirements.assert(:install, :set, :remove) do |a| a.assertion do !new_resource.path.nil? end a.failure_message("Could not set alternatives for #{new_resource.link_name}, you must provide the :path property") end requirements.assert(:install, :set, :remove) do |a| a.assertion do ::TargetIO::File.exist?(new_resource.path) end a.whyrun("Assuming file #{new_resource.path} already exists or was created already") a.failure_message("Could not set alternatives for #{new_resource.link_name}, missing #{new_resource.path}") end end
path_exists?()
click to toggle source
@return [Boolean] does the path exist for the link_name alternative
# File lib/chef/resource/alternatives.rb, line 201 def path_exists? # https://rubular.com/r/ogvDdq8h2IKRff escaped_path = Regexp.new(Regexp.escape("#{new_resource.path} - priority")) shell_out(alternatives_cmd, "--display", new_resource.link_name).stdout.match?(escaped_path) end
path_priority()
click to toggle source
@return [Integer] The current path priority for the link_name alternative
# File lib/chef/resource/alternatives.rb, line 181 def path_priority # https://rubular.com/r/IcUlEU0mSNaMm3 escaped_path = Regexp.new(Regexp.escape("#{new_resource.path} - priority ") + "(.*)") match = shell_out(alternatives_cmd, "--display", new_resource.link_name).stdout.match(escaped_path) match.nil? ? nil : match[1].to_i end