Skip to content

Commit

Permalink
Apply code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Sija committed Mar 6, 2023
1 parent 8d56f22 commit 4c59858
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/ameba/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,25 @@ class Ameba::Config
raise "Config file is invalid: #{e.message}"
end

protected def self.read_config(path) : String?
protected def self.read_config(path = nil)
if path
return File.exists?(path) ? File.read(path) : nil
end
path = Path[DEFAULT_PATH].expand(home: true)
each_config_path do |config_path|
return File.read(config_path) if File.exists?(config_path)
end
end

search_paths = path
.parents
.map! { |search_path| search_path / FILENAME }
protected def self.each_config_path(&)
path = Path[DEFAULT_PATH].expand(home: true)

search_paths = path.parents
search_paths.reverse_each do |search_path|
return File.read(search_path) if File.exists?(search_path)
yield search_path / FILENAME
end

DEFAULT_PATHS.each do |default_path|
return File.read(default_path) if File.exists?(default_path)
yield default_path
end
end

Expand Down

0 comments on commit 4c59858

Please sign in to comment.