class ActiveRecordDoctor::Runner
An excecution environment for active_record_doctor that provides a config and an output device for use by detectors.
Attributes
config[R]
io[R]
logger[R]
Public Class Methods
new(config:, logger:, io: $stdout)
click to toggle source
io is injected via constructor parameters to facilitate testing.
# File lib/active_record_doctor/runner.rb, line 8 def initialize(config:, logger:, io: $stdout) @config = config @logger = logger @io = io end
Public Instance Methods
help(name)
click to toggle source
# File lib/active_record_doctor/runner.rb, line 37 def help(name) detector = ActiveRecordDoctor.detectors.fetch(name) io.puts(ActiveRecordDoctor::Help.new(detector)) end
run_all()
click to toggle source
# File lib/active_record_doctor/runner.rb, line 24 def run_all success = true # We can't use #all? because of its short-circuit behavior - it stops # iteration and returns false upon the first falsey value. This # prevents other detectors from running if there's a failure. ActiveRecordDoctor.detectors.each do |name, _| success = false if !run_one(name) end success end
run_one(name)
click to toggle source
# File lib/active_record_doctor/runner.rb, line 14 def run_one(name) ActiveRecordDoctor.handle_exception do ActiveRecordDoctor.detectors.fetch(name).run( config: config, logger: logger, io: io ) end end