Class: Conf
- Inherits:
-
Object
- Object
- Conf
- Defined in:
- lib/vpsmatrix/config.rb
Instance Method Summary collapse
- #content ⇒ Object
-
#initialize(home = nil) ⇒ Conf
constructor
A new instance of Conf.
-
#write(key, value) ⇒ Object
how to write with nested keys.
Constructor Details
#initialize(home = nil) ⇒ Conf
Returns a new instance of Conf.
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/vpsmatrix/config.rb', line 4 def initialize(home=nil) @file_path = ".vpsx.yml" @file_path = "#{ENV['HOME']}/.vpsx.yml" if home unless File.exists? @file_path File.open(@file_path, 'w') do |file| file.write "comment: 'Config file for VPS Matrix services'" end end @content = YAML::load_file(@file_path) end |
Instance Method Details
#content ⇒ Object
15 16 17 |
# File 'lib/vpsmatrix/config.rb', line 15 def content @content end |
#write(key, value) ⇒ Object
how to write with nested keys
20 21 22 23 |
# File 'lib/vpsmatrix/config.rb', line 20 def write key, value @content[key] = value File.open(@file_path, 'w') { |f| YAML.dump(@content, f) } end |