lib/inspec/resources/yum.rb in inspec-4.7.3 vs lib/inspec/resources/yum.rb in inspec-4.7.18

- old
+ new

@@ -45,10 +45,11 @@ # parse data in hashmap # store data in object # until \n def repositories return @cache if defined?(@cache) + # parse the repository data from yum # we cannot use -C, because this is not reliable and may lead to errors @command_result = inspec.command("yum -v repolist all") @content = @command_result.stdout @cache = [] @@ -80,11 +81,11 @@ YumRepo.new(self, repo) end # alias for yum.repo('reponame') def method_missing(name) - repo(name.to_s) if !name.nil? + repo(name.to_s) unless name.nil? end def to_s "Yum Repository" end @@ -97,10 +98,11 @@ end # Optimize the key value def repo_key(key) return key if key.nil? + key.gsub("Repo-", "").downcase end end class YumRepo @@ -116,10 +118,11 @@ val.nil? ? nil : val[1] end def info return @cache if defined?(@cache) + selection = @yum.repositories.select { |e| e["id"] == @reponame || shortname(e["id"]) == @reponame } @cache = selection.empty? ? {} : selection.first @cache end @@ -127,23 +130,24 @@ !info.empty? end def enabled? return false unless exist? + info["status"] == "enabled" end # provide a method for each of the repo metadata items we know about - [ - :baseurl, - :expire, - :filename, - :mirrors, - :pkgs, - :size, - :status, - :updated, - ].each do |key| + %i{ + baseurl + expire + filename + mirrors + pkgs + size + status + updated + }.each do |key| define_method key do info[key.to_s] end end