X-Git-Url: https://git.r.bdr.sh/rbdr/lyricli.rb/blobdiff_plain/b9f550e97a60c4953fd1ae9374045110836764bd..4f3dbb13d02f6eb2ac2b8fea1879e9d5150166b1:/lib/lyricli/configuration.rb 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