Class: ActiveRecordDoctor::Runner
- Inherits:
-
Object
- Object
- ActiveRecordDoctor::Runner
- Defined in:
- lib/active_record_doctor/runner.rb
Overview
An execution environment for active_record_doctor that provides a config and an output device for use by detectors.
Instance Method Summary collapse
- #help(name) ⇒ Object
-
#initialize(config:, logger:, io: $stdout) ⇒ Runner
constructor
io is injected via constructor parameters to facilitate testing.
- #run_all ⇒ Object
- #run_one(name) ⇒ Object
Constructor Details
#initialize(config:, logger:, io: $stdout) ⇒ Runner
io is injected via constructor parameters to facilitate testing.
8 9 10 11 12 |
# File 'lib/active_record_doctor/runner.rb', line 8 def initialize(config:, logger:, io: $stdout) @config = config @logger = logger @io = io end |
Instance Method Details
#help(name) ⇒ Object
37 38 39 40 |
# 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 ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# 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) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# 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 |