X-Git-Url: https://git.r.bdr.sh/rbdr/lyricli.rb/blobdiff_plain/823e558b5cd2ec219d0fc7226c54f2ee7ad807d2..1be0eee39d325c1a180dbf992bc6fd256f828008:/lib/lyricli/configuration.rb?ds=inline diff --git a/lib/lyricli/configuration.rb b/lib/lyricli/configuration.rb index 8d26b7f..0311017 100644 --- a/lib/lyricli/configuration.rb +++ b/lib/lyricli/configuration.rb @@ -24,22 +24,24 @@ module Lyricli save_config end - private_class_method :new + def delete(key) + load_config unless @config + @config.delete(key) + save_config + end - private + private_class_method :new # TODO: Apart from this, load a default yml that will be used for this. # And just extend everything from the user's config. def load_config - # path = File.expand_path(@config_path) - path_root = File.expand_path(File.dirname(__FILE__)) - path = File.join(path_root, @defaults_path) + path = File.expand_path(@config_path) if File.exists?(path) file = File.new(path, "r") @config = MultiJson.decode(file.read) else - @config = {} + load_default_config end end @@ -49,5 +51,20 @@ module Lyricli file.print(MultiJson.encode(@config)) file.close end + + private + + def load_default_config + # Load the default + path_root = File.expand_path(File.dirname(__FILE__)) + path = File.join(path_root, @defaults_path) + + if File.exists?(path) + file = File.new(path, "r") + @config = MultiJson.decode(file.read) + else + @config = {} + end + end end end