mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Apply code review suggestions
This commit is contained in:
parent
8d56f22af1
commit
4c59858f25
1 changed files with 10 additions and 7 deletions
|
@ -114,22 +114,25 @@ class Ameba::Config
|
||||||
raise "Config file is invalid: #{e.message}"
|
raise "Config file is invalid: #{e.message}"
|
||||||
end
|
end
|
||||||
|
|
||||||
protected def self.read_config(path) : String?
|
protected def self.read_config(path = nil)
|
||||||
if path
|
if path
|
||||||
return File.exists?(path) ? File.read(path) : nil
|
return File.exists?(path) ? File.read(path) : nil
|
||||||
end
|
end
|
||||||
|
each_config_path do |config_path|
|
||||||
|
return File.read(config_path) if File.exists?(config_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
protected def self.each_config_path(&)
|
||||||
path = Path[DEFAULT_PATH].expand(home: true)
|
path = Path[DEFAULT_PATH].expand(home: true)
|
||||||
|
|
||||||
search_paths = path
|
search_paths = path.parents
|
||||||
.parents
|
|
||||||
.map! { |search_path| search_path / FILENAME }
|
|
||||||
|
|
||||||
search_paths.reverse_each do |search_path|
|
search_paths.reverse_each do |search_path|
|
||||||
return File.read(search_path) if File.exists?(search_path)
|
yield search_path / FILENAME
|
||||||
end
|
end
|
||||||
|
|
||||||
DEFAULT_PATHS.each do |default_path|
|
DEFAULT_PATHS.each do |default_path|
|
||||||
return File.read(default_path) if File.exists?(default_path)
|
yield default_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue