From f6abe8f0e87de9a68a32b6398ce2f47ddfb33aa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A8r=20Kessels?= Date: Mon, 4 Nov 2019 12:13:27 +0100 Subject: [PATCH] Use superclass defaults rather than relying on copied defaults. This allows '#' as comment, as the superclass allows. It also means we don't have to keep our hardcoded defaults in sync with the superclass. --- lib/todotxt/config.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/todotxt/config.rb b/lib/todotxt/config.rb index f386cb9..76b9f0d 100644 --- a/lib/todotxt/config.rb +++ b/lib/todotxt/config.rb @@ -12,22 +12,23 @@ class Config < ParseConfig def initialize(options = {}) @options = options - @config_file = options[:config_file] || Config.config_path + # Superclass will flunk if @config_file is set but not readable. + # But we need to be able to handle that situation. Hence we shadow + # the original @config_file and set it manually after initializing. + @try_config_file = options[:config_file] || Config.config_path if file_exists? super @config_file validate else - # Initialize mandatory values for `ParseConfig` - @params = {} - @groups = [] - @splitRegex = '\s*=\s*' - @comments = [';'] + super(nil) end + + @config_file = @try_config_file end def file_exists? - File.exist? @config_file + File.exists? @config_file || @try_config_file end def files