Module: OssStats::Config::Shared
- Included in:
- MeetingStats, Promises, RepoStats
- Defined in:
- lib/oss_stats/config/shared.rb
Instance Method Summary collapse
-
#find_config_file(filename) ⇒ Object
a common method among all config parsers to find the config file.
Instance Method Details
#find_config_file(filename) ⇒ Object
a common method among all config parsers to find the config file
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/oss_stats/config/shared.rb', line 8 def find_config_file(filename) log.debug("#{name}: config_file called") # Check to see if `config` has been defined # in the current config, and if so, return that. # # Slight magic here, name will be, for example # OssStats::Config::RepoStats # So we trip the first part and get just `RepoStats`, # then get the class, and check for config, akin to doing # # if OssStats::Config::RepoStats.config # return OssStats::Config::RepoStats.config # end kls = name.sub('OssStats::Config::', '') config_class = OssStats::Config.const_get(kls) if config_class.config return config_class.config end # otherwise, we check CWD, XDG, and /etc. [ Dir.pwd, File.join(ENV['HOME'], '.config', 'oss_stats'), '/etc', ].each do |dir| f = File.join(dir, filename) log.debug("[#{name}] Checking if #{f} exists...") return f if ::File.exist?(f) end nil end |