summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-03-12 12:52:34 -0700
committerTim Smith <tsmith84@gmail.com>2020-03-12 12:52:34 -0700
commit26a0a6c55d40f3263600c2ba9ad684732932552b (patch)
treec54e379a96ef5da1d006ccb71cf043e2b80d86ba
parent907320671110830aea04219422c8e53e9e88280f (diff)
downloadchef-26a0a6c55d40f3263600c2ba9ad684732932552b.tar.gz
Use match? and add some yard
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource/alternatives.rb15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/chef/resource/alternatives.rb b/lib/chef/resource/alternatives.rb
index a85a2bb138..25cf04dbdc 100644
--- a/lib/chef/resource/alternatives.rb
+++ b/lib/chef/resource/alternatives.rb
@@ -98,6 +98,9 @@ class Chef
end
action_class do
+ #
+ # @return [String] The appropriate alternatives command based on the platform
+ #
def alternatives_cmd
if fedora_derived?
"alternatives"
@@ -106,6 +109,10 @@ class Chef
end
end
+
+ #
+ # @return [Integer] The current path priority for the link_name alternative
+ #
def path_priority
# https://rubular.com/r/IcUlEU0mSNaMm3
escaped_path = Regexp.new(Regexp.escape("#{new_resource.path} - priority ") + "(.*)")
@@ -114,16 +121,22 @@ class Chef
match.nil? ? nil : match[1].to_i
end
+ #
+ # @return [String] The current path for the link_name alternative
+ #
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.nil? ? nil : match[1]
end
+ #
+ # @return [Boolean] does the path exist for the link_name alternative
+ #
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)
+ shell_out("#{alternatives_cmd} --display #{new_resource.link_name}").stdout.match?(escaped_path)
end
end
end