Class: ActiveRecordDoctor::Loader
- Inherits:
-
Object
- Object
- ActiveRecordDoctor::Loader
- Defined in:
- lib/active_record_doctor/config/loader.rb
Overview
A class used for loading user-provided configuration files.
Instance Method Summary collapse
- #detector(name, settings) ⇒ Object
- #global(name, value) ⇒ Object
-
#initialize(config, recognized_globals, recognized_detectors, &block) ⇒ Loader
constructor
A new instance of Loader.
Constructor Details
#initialize(config, recognized_globals, recognized_detectors, &block) ⇒ Loader
Returns a new instance of Loader.
82 83 84 85 86 87 |
# File 'lib/active_record_doctor/config/loader.rb', line 82 def initialize(config, recognized_globals, recognized_detectors, &block) @config = config @recognized_globals = recognized_globals @recognized_detectors = recognized_detectors instance_eval(&block) end |
Instance Method Details
#detector(name, settings) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/active_record_doctor/config/loader.rb', line 106 def detector(name, settings) name = name.to_sym recognized_settings = recognized_detectors[name] if recognized_settings.nil? raise ActiveRecordDoctor::Error::UnrecognizedDetectorName[ name, recognized_detectors.keys ] end if config.detectors.include?(name) raise ActiveRecordDoctor::Error::DetectorConfiguredTwice[name] end unrecognized_settings = settings.keys - recognized_settings unless unrecognized_settings.empty? raise ActiveRecordDoctor::Error::UnrecognizedDetectorSettings[ name, unrecognized_settings, recognized_settings ] end config.detectors[name] = settings end |
#global(name, value) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/active_record_doctor/config/loader.rb', line 89 def global(name, value) name = name.to_sym unless recognized_globals.include?(name) raise ActiveRecordDoctor::Error::UnrecognizedGlobalSetting[ name, recognized_globals ] end if config.globals.include?(name) raise ActiveRecordDoctor::Error::DuplicateGlobalSetting[name] end config.globals[name] = value end |