]> git.r.bdr.sh - rbdr/lyricli.rb/blobdiff - lib/lyricli/configuration.rb
Add a README
[rbdr/lyricli.rb] / lib / lyricli / configuration.rb
index 8d26b7f179c8bd48b7539a1b0fae3131aabb81e7..031101720bc87ee74b6bbdec421fb5908cec1cfd 100644 (file)
@@ -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