class Yum
def method_missing(name)
def method_missing(name) repo(name.to_s) if !name.nil? end
def repo(repo)
def repo(repo) YumRepo.new(self, repo) end
def repo_key(key)
def repo_key(key) return key if key.nil? key.gsub('Repo-', '').downcase end
def repos
def repos repositories.map { |repo| repo['id'] } end
def repositories
store data in object
parse data in hashmap
search for Repo-id
works as following:
returns all repositories
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 = [] repo = {} in_repo = false @content.each_line do |line| # detect repo start in_repo = true if line =~ /^\s*Repo-id\s*:\s*(.*)\b/ # detect repo end if line == "\n" && in_repo in_repo = false @cache.push(repo) repo = {} end # parse repo content if in_repo == true val = /^\s*([^:]*?)\s*:\s*(.*?)\s*$/.match(line) repo[repo_key(strip(val[1]))] = strip(val[2]) end end @cache end
def strip(value)
def strip(value) value.strip if !value.nil? end
def to_s
def to_s 'Yum Repository' end