Reimplemented Manager as singleton object

This commit is contained in:
Tristan Ancelet 2024-06-29 13:08:05 -05:00
parent 0897af3654
commit 7f8173ebf7

View File

@ -1,25 +1,30 @@
module RubyQA module RubyQA
class Manager class Manager
attr_reader :resources attr_reader :resources, :hosts
@@tests = Array.new @@tests = Array.new
@@hosts = Array.new
def initialize def self.tests
@hosts = Array.new @@tests
end end
def add_host(host) def self.hosts
@hosts << host @@hosts
end
def self.add_host(host)
@@hosts << host
register_resources(host) register_resources(host)
update_resources(host) update_resources(host)
end end
def register_resources (host) def self.register_resources (host)
Resource.all_resources.each do |resource| Resource.all_resources.each do |resource|
host.add_resource(resource) host.add_resource(resource)
end end
end end
def update_resources (host) def self.update_resources (host)
host.update_resources host.update_resources
end end
@ -27,8 +32,8 @@ module RubyQA
@@tests << Test.new(name, **options, &test_proc) @@tests << Test.new(name, **options, &test_proc)
end end
def run_tests def self.run_tests
@hosts.each do |host| @@hosts.each do |host|
tests = @@tests.select{|test| test.valid_host(host)} tests = @@tests.select{|test| test.valid_host(host)}
tests.each do |test| tests.each do |test|
test.run(host) test.run(host)
@ -36,8 +41,12 @@ module RubyQA
end end
end end
def report def self.report (template = nil)
if template
puts template.result(binding)
else
puts @@tests.map(&:report).join("\n") puts @@tests.map(&:report).join("\n")
end end
end end
end
end end