Module: Aocli::Config
- Defined in:
- lib/aocli/config.rb
Class Method Summary collapse
- .add_config(key:, value:) ⇒ Object
- .load_config ⇒ Object
- .remove_config(key) ⇒ Object
- .value_for(key) ⇒ Object
Class Method Details
.add_config(key:, value:) ⇒ Object
5 6 7 8 |
# File 'lib/aocli/config.rb', line 5 def add_config(key:, value:) config = load_config.merge({key => value}) File.write(Aocli::Values::CONFIG_FILE_PATH, config.to_yaml) end |
.load_config ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/aocli/config.rb', line 14 def load_config unless File.exist?(Aocli::Values::CONFIG_FILE_PATH) Aocli::FileUtils.touch_file(Aocli::Values::CONFIG_FILE_PATH) end YAML.load_file(Aocli::Values::CONFIG_FILE_PATH, fallback: {}) end |
.remove_config(key) ⇒ Object
22 23 24 25 26 |
# File 'lib/aocli/config.rb', line 22 def remove_config(key) config = load_config File.write(Aocli::Values::CONFIG_FILE_PATH, config.except(key).to_yaml) end |
.value_for(key) ⇒ Object
10 11 12 |
# File 'lib/aocli/config.rb', line 10 def value_for(key) load_config[key] end |