Class: Lyricli::Configuration
- Inherits:
-
Object
- Object
- Lyricli::Configuration
- Defined in:
- lib/lyricli/configuration.rb
Constant Summary
- @@instance =
Configuration.new
Class Method Summary (collapse)
Instance Method Summary (collapse)
- - (Object) [](key)
- - (Object) []=(key, value)
- - (Object) delete(key)
-
- (Configuration) initialize
constructor
A new instance of Configuration.
-
- (Object) load_config
TODO: Apart from this, load a default yml that will be used for this.
- - (Object) save_config
Constructor Details
- (Configuration) initialize
A new instance of Configuration
4 5 6 7 8 |
# File 'lib/lyricli/configuration.rb', line 4 def initialize @config_path = "~/.lyricli.conf" @defaults_path = "defaults.json" @config = nil end |
Class Method Details
+ (Object) instance
12 13 14 |
# File 'lib/lyricli/configuration.rb', line 12 def self.instance @@instance end |
Instance Method Details
- (Object) [](key)
16 17 18 19 |
# File 'lib/lyricli/configuration.rb', line 16 def [](key) load_config unless @config @config[key] end |
- (Object) []=(key, value)
21 22 23 24 25 |
# File 'lib/lyricli/configuration.rb', line 21 def []=(key, value) load_config unless @config @config[key] = value save_config end |
- (Object) delete(key)
27 28 29 30 31 |
# File 'lib/lyricli/configuration.rb', line 27 def delete(key) load_config unless @config @config.delete(key) save_config end |
- (Object) load_config
TODO: Apart from this, load a default yml that will be used for this. And just extend everything from the user’s config.
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/lyricli/configuration.rb', line 37 def load_config path = File.(@config_path) if File.exists?(path) file = File.new(path, "r") @config = MultiJson.decode(file.read) else load_default_config end end |
- (Object) save_config
48 49 50 51 52 53 |
# File 'lib/lyricli/configuration.rb', line 48 def save_config path = File.(@config_path) file = File.new(path, "w") file.print(MultiJson.encode(@config)) file.close end |