]> git.r.bdr.sh - rbdr/lyricli.rb/blame - lib/lyricli/config.rb
First Batch of Source Changes [Broken]
[rbdr/lyricli.rb] / lib / lyricli / config.rb
CommitLineData
b8498f5c
BB
1module Lyricli
2 class Config
3
4 def initialize
5 @config_path = "~/.lyricli.conf"
6 @config = load_config
7 end
8
9 @@instance = Config.new
10
11 def self.instance
12 @@instance
13 end
14
15 def [](key)
16 @config[key]
17 end
18
19 def []=(key, value)
20 @config[key] = value
21 save_config
22 end
23
24 private_class_method :new
25
26 private
27
28 # TODO: Apart from this, load a default yml that will be used for this.
29 # And just extend everything from the user's config.
30 def load_config
31 path = File.expand_path(@config_path)
32 if File.exists?(path)
33 file = File.new(path, "r")
34 MultiJson.decode(file.read)
35 else
36 {}
37 end
38 end
39
40 def save_config
41 path = File.expand_path(@config_path)
42 file = File.new(path, "w")
43 file.print(MultiJson.encode(@config))
44 file.close
45 end
46 end
47end